Displays one of a set of possible outputs, depending on the relative value of its two input parameters.
Class Name |
|
---|---|
Component |
|
Required 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 no open parameter corresponds to the comparison result. For example, obj1
is greater than obj2
and there is no greaterthan
open parameter; or the obj1
and obj2
cannot be compared and there is no noncomparable
parameter.
Usage Notes
Compare 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
.
Example
The following example uses Compare 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"></dsp:include> </dsp:oparam> <dsp:oparam name="default"> <%-- user has logged in, so proceed to the protected content --%> <dsp:include page="protected_content.jsp"></dsp:include> </dsp:oparam> </dsp:droplet>