|
Initially we set default values for these attributes in the UserAction.
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception {
ArrayList hobbiesList = new ArrayList();
UserForm userForm = (UserForm)form;
userForm.setName("Eswar");
userForm.setAge(21);
userForm.setHeight(5.11f);
userForm.setWeight(70f);
userForm.setFavouriteFood("Fish and Chicken");
hobbiesList.add("Music");
hobbiesList.add("Art");
hobbiesList.add("Dance");
userForm.setHobbies(hobbiesList);
return mapping.findForward(SUCCESS);
}
Based on the conditions specified using the logic tags in the jsp page, the corresponding messages will be displayed to the user.
<logic:present /> <logic:notPresent />
The following code will dispaly "The User Name is Eswar." if the name attribute has some value else it will display "The User is not Present."
<logic:present name="UserForm" property="name">
The User Name is Eswar.
</logic:present>
<logic:notPresent name="UserForm" property="name">
The User is not Present.
</logic:notPresent>
<logic:equal /> <logic:notEqual />
The following code will dispaly "The age is equal to 18." if the value of the age attribute is 18 else it will dispaly "The age is not equal to 18."
<logic:equal name="UserForm" property="age" value="18">
The age is equal to 18.
</logic:equal>
<logic:notEqual name="UserForm" property="age" value="18">
The age is not equal to 18.
</logic:notEqual>
<logic:greaterEqual /> <logic:greaterThan />
The following code will dispaly "The height is greater than or equal to 5.11" if the value of the height attribute is equal to or greater than 5.11 else it will display "The height is greater than 5.11" if the value of the height attribute is greater than 5.11.
<logic:greaterEqual name="UserForm" property="height" value="5.11">
The height is greater than or equal to 5.11
</logic:greaterEqual>
<logic:greaterThan name="UserForm" property="height" value="5.11">
The height is greater than 5.11
</logic:greaterThan>
<logic:lessEqual /> <logic:lessThan />
The following code will dispaly "The weight is less than or equal to 70." if the value of the weight attribute is less than or equal to 70 else it will display "The weight is less than 70" if the value of the weight attribute is less than 70.
<logic:lessEqual name="UserForm" property="weight" value="70">
The weight is less than or equal to 70.
</logic:lessEqual>
<logic:lessThan name="UserForm" property="weight" value="70">
The weight is less than 70.
</logic:lessThan>
<logic:match /> <logic:notMatch />
The following code will display "The user's favourite food includes Chicken" if the value of the favouriteFood attribute contains "Chicken" else it will display "The user's favourite food does not include Chicken".
<logic:match name="UserForm" property="favouriteFood" value="Chicken">
The user's favourite food includes Chicken.
</logic:match>
<logic:notMatch name="UserForm" property="favouriteFood" value="Chicken">
The user's favourite food does not includes Chicken.
</logic:notMatch>
<logic:iterate />
The following code is used to iterate the ArrayList and display the contents.
<logic:iterate name="UserForm" property="hobbies" id="data">
<bean:write name="data" />
</logic:iterate>
On executing the example the following page will be displayed to the user.
|