Home Struts Struts Struts2.2.1 Tags struts2.2.1 checkboxlist tag example.

Ask Questions?

View Latest Questions


 
 

struts2.2.1 checkboxlist tag example.
Posted on: January 10, 2011 at 12:00 AM
Advertisement
In this turtorial, you will see the use of  checkboxlist tag example of struts2.2.1.

struts2.2.1 checkboxlist tag example.

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>

<head><title>Struts2.2.1_CheckBoxList_Tag</title></head>

<body>

<h1>Struts2.2.1_CheckBoxList_Tag</h1><hr/>

<a href="checkBoxListAction.action">CheckBoxList Example</a>

</body>

</html>

2-checkBoxList.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>

<html>

<head><title>Struts2.2.1_CheckBoxList_Tag</title></head>

<body>

<h1>Struts2.2.1_CheckBoxList_Tag</h1><hr/>

<s:form action="resultAction" namespace="/">

<h4>

<s:checkboxlist label="Select Cities" list="cities" name="mycity" />

</h4><s:submit value="submit" name="submit" />

</s:form></body>

</html>

 

3-CheckBoxListAction.java

package roseindia;

import java.util.ArrayList;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class CheckBoxListAction extends ActionSupport {

private List<String> cities;

private String mycity;

public String getMycity() {

return mycity;

}

public void setMycity(String mycity) {

this.mycity = mycity;

}

public List<String> getCities() {

return cities;

}

public void setCities(List<String> cities) {

this.cities = cities;

}

public CheckBoxListAction() {

cities=new ArrayList<String>();

cities.add("Bareilly");

cities.add("Lucknow");

cities.add("Dehli");

cities.add("Noida");

}

public String execute() {

return SUCCESS;

}

public String display() {

return NONE;}

}

4_struts.xml

<struts>

<constant name="struts.devMode" value="false" />

<package name="default" namespace="/" extends="struts-default">

<action name="comboBoxAction"

class="roseindia.ComboBoxAction" method="display">

<result name="none">pages/combobox.jsp</result></action>

<action name="comboBoxResult" class="roseindia.ComboBoxAction">

<result name="success">pages/comboBoxResult.jsp</result></action>

</package>

</struts>

5.comboBoxResult.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>

<html>

<head><title>Struts2.2.1_CheckBoxList_Tag</title></head>

<body>

<h1>Struts2.2.1_CheckBoxList_Tag</h1><hr/>

<b>Your city :</b> <s:property value="mycity"/>

</body>

</html>

 

indexJsp.gif

combobox.gif

selectValue.gif

DisplayValue.gif

Download Select Source Code


Related Tags for struts2.2.1 checkboxlist tag example.:


DMCA.com