Name:
Location: Bangalore, India

Sunday, November 04, 2007

Displaying Yes/No in place of Y/N

To display the "Yes" and "No" values on screen. Helps to convert "Y" to "Yes" and "N" to "No". We have a drop down with
1. Select a value
2. Y
3. N

logic:present helps us to find if the property is not a null value in the form.
logic:notEqual helps us to check whether the property is not equal to the value given in the value attribute of this tag.
An example for this would be a drop-down where we have (1) select a value (2) Yes (3) No.
Here option 1 is the default value and if user selects this value then the property (yesnovalue) would be set to nothing which is obviously a empty string. To check for this condition we use
logic:notEqual

<logic:present name="abcForm" property="yesnovalue">
<logic:notEqual name="abcForm" property="yesnovalue" value="">
<bean:message key='common.label.${abcForm.yesnovalue}' bundle="abc"/>
</logic:notEqual>

${abcForm.yesnovalue} ==> This is nothing but the Expression Language (EL) to send the value to the (Yes/No) dynamically to the ApplicationResources.properties file.

Define these values in application resources bundle

common.label.Y=Yes
common.label.N=No

If Expression Language (EL) is not allowed we can directly use struts tags

<logic:present name="RequestForm" property="priority">
<logic:notEmpty name="RequestForm" property="priority">
<logic:equal name="RequestForm" property="priority" value="N">
<bean:message key="request.label.priorityNormal" bundle="gtem" />
</logic:equal>
<logic:equal name="RequestForm" property="priority" value="Y">
<bean:message key="request.label.priorityUrgent" bundle="gtem" />
</logic:equal>
</logic:notEmpty>
</logic:present>

0 Comments:

Post a Comment

<< Home