ClassName |
|
---|---|
Component |
|
The Compare
servlet bean takes two objects as input parameters and conditionally renders one of its open parameters, based on the relative values of the input parameters. For all non-number properties, the comparison is accomplished by casting the two objects to java.lang.Comparable
and calling Comparable.compareTo()
. A comparison must involve properties that share the same data type, unless those properties are instances of java.lang.Number
.
Input Parameters
obj1 and obj2
The objects to compare.
Open Parameters
greaterthan
The value to render if obj1
is greater than obj2
.
lessthan
The value to render if obj1
is less than obj2
.
equal
The value to render if obj1
is equal to obj2
.
noncomparable
The value to render if obj1
and obj2
cannot be compared.
default
The value to render if there is no open parameter corresponding to the result of the comparison (for example, if obj1 is greater than obj2 but there is no greaterthan
open parameter, or the two objects cannot be compared and there is no noncomparable
parameter).
Example
The following example uses the Compare
servlet bean to compare the value of the securityStatus
property of the user’s profile to the value of the securityStatusLogin
property of the PropertyManager
component, to determine whether the user has logged in.
<dsp:droplet name="Compare"> <dsp:param name="obj1" bean="Profile.securityStatus"/> <dsp:param name="obj2" bean="PropertyManager.securityStatusLogin"/> <dsp:oparam name="lessthan"> <%-- user has not logged in, so display the login form --%> <dsp:include page="login_form.jsp" flush="true"></dsp:include> </dsp:oparam> <dsp:oparam name="default"> <%-- user has logged in, so proceed to the protected content --%> <dsp:include page="protected_content.jsp" flush="true"></dsp:include> </dsp:oparam> </dsp:droplet>