In this turtorial, you will see the use of checkboxlist tag example of struts2.2.1.The checkboxlist tag is a UI tag that creates a series of checkboxes from a list. Setup is like <s:select /> or <s:radio />, but creates checkbox tags.
Directory structure of CheckBoxList tag example.1- index.html
<html>ADS_TO_REPLACE_1 <head><title>Struts2.2.1_CheckBoxList_Tag</title></head> <body> <h1>Struts2.2.1_CheckBoxList_Tag</h1><hr/>ADS_TO_REPLACE_2 <a href="checkBoxListAction.action">CheckBoxList Example</a> </body> </html> |
2-checkBoxList.jsp ADS_TO_REPLACE_3
<%@ taglib prefix="s" uri="/struts-tags" %> <html> <head><title>Struts2.2.1_CheckBoxList_Tag</title></head>ADS_TO_REPLACE_4 <body> <h1>Struts2.2.1_CheckBoxList_Tag</h1><hr/> <s:form action="resultAction" namespace="/">ADS_TO_REPLACE_5 <h4> <s:checkboxlist label="Select Cities" list="cities" name="mycity" /> </h4><s:submit value="submit" name="submit" />ADS_TO_REPLACE_6 </s:form></body> </html> |
3-CheckBoxListAction.java
package roseindia;ADS_TO_REPLACE_7 import java.util.ArrayList; import java.util.List; import com.opensymphony.xwork2.ActionSupport;ADS_TO_REPLACE_8 public class CheckBoxListAction extends ActionSupport { private List<String> cities; private String mycity;ADS_TO_REPLACE_9 public String getMycity() { return mycity; }ADS_TO_REPLACE_10 public void setMycity(String mycity) { this.mycity = mycity; }ADS_TO_REPLACE_11 public List<String> getCities() { return cities; }ADS_TO_REPLACE_12 public void setCities(List<String> cities) { this.cities = cities; }ADS_TO_REPLACE_13 public CheckBoxListAction() { cities=new ArrayList<String>(); cities.add("Bareilly");ADS_TO_REPLACE_14 cities.add("Lucknow"); cities.add("Dehli"); cities.add("Noida");ADS_TO_REPLACE_15 } public String execute() { return SUCCESS;ADS_TO_REPLACE_16 } public String display() { return NONE;}ADS_TO_REPLACE_17 } |
4_struts.xml
<struts> <constant name="struts.devMode" value="false" /> <package name="default" namespace="/" extends="struts-default">ADS_TO_REPLACE_18 <action name="comboBoxAction" class="roseindia.ComboBoxAction" method="display"> <result name="none">pages/combobox.jsp</result></action>ADS_TO_REPLACE_19 <action name="comboBoxResult" class="roseindia.ComboBoxAction"> <result name="success">pages/comboBoxResult.jsp</result></action> </package>ADS_TO_REPLACE_20 </struts> |
5.comboBoxResult.jsp
<%@ taglib prefix="s" uri="/struts-tags" %> <html> <head><title>Struts2.2.1_CheckBoxList_Tag</title></head>ADS_TO_REPLACE_21 <body> <h1>Struts2.2.1_CheckBoxList_Tag</h1><hr/> <b>Your city :</b> <s:property value="mycity"/>ADS_TO_REPLACE_22 </body> </html> |
indexJsp.gif
ADS_TO_REPLACE_23
combobox.gif
selectValue.gifADS_TO_REPLACE_24
DisplayValue.gif
ADS_TO_REPLACE_25
Advertisements
Ads
Ads