Struts2.2.1 doubleselect tag example.
Posted on: January 15, 2011 at 12:00 AM
In this tutorial, you will see the use of doubleselect tag of struts2.2.1.

Struts2.2.1 doubleselect tag example.

In this tutorial, you will see the use of doubleselect tag of struts2.2.1. the <s:doubleselect> tag is used to create two HTML drop down boxes, 
once the first drop down list is selected, the second drop down list will be change accordingly. In this example ?Degree? and ?Diploma? drop down selection, where different ?Degree? lists are depending on the selected ?Degree? or "Diploma".

Directory structure of doubleselect tag example.

 1- index.jspADS_TO_REPLACE_1

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">ADS_TO_REPLACE_2

<title>DoubleSelect Tag Example</title>

</head>

<body>ADS_TO_REPLACE_3

<a href="DoubleSelectTag.action">DoubleSelect Tag Example</a>

</body>

</html>

2-DoubleSelectTag.jspADS_TO_REPLACE_4

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

<html>

<head>ADS_TO_REPLACE_5

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>DoubleSelect Tag Example</title>

</head>ADS_TO_REPLACE_6

<body>

<s:form action="DoubleSelectResult">

<s:textfield name="name" key="Name"></s:textfield>ADS_TO_REPLACE_7

<table>

<tr>

<td>Select your Qualification: <s:doubleselectADS_TO_REPLACE_8

label="Qualification" name="list1"

doubleList="top == 'Degree' ? {'MCA', 'MBA','MTech','BTech','MSc(IT)'} :

{'PGDCA', 'PGDM','PGDBM','PGDSM'}"ADS_TO_REPLACE_9

list="{'Degree','Diploma'}" doubleName="list2" /></td>

</tr>

<tr>ADS_TO_REPLACE_10

<td>Select your Experience: <s:doubleselect label="Experience"

name="list3"

doubleList="top == 'Fresher' ? {'2009', '2010','2011'} :ADS_TO_REPLACE_11

{'6 months','6+months','1 year','1+year','2+year'}"

list="{'Fresher','Experience'}" doubleName="list4" /></td>

</tr>ADS_TO_REPLACE_12

<tr>

<td><s:submit></s:submit></td>

</tr>ADS_TO_REPLACE_13

</table>

</s:form>

</body>ADS_TO_REPLACE_14

</html>

 3-DoubleSelectTag.java

package roseindia;

import com.opensymphony.xwork2.ActionSupport;ADS_TO_REPLACE_15

public class DoubleSelectTag extends ActionSupport {

private String list1;

private String list2;ADS_TO_REPLACE_16

private String list3;

private String list4;

private String name;ADS_TO_REPLACE_17

public String execute() throws Exception {

return SUCCESS;

}ADS_TO_REPLACE_18

public String getList1() {

return list1;

}ADS_TO_REPLACE_19

public void setList1(String list1) {

this.list1 = list1;

}ADS_TO_REPLACE_20

public String getList2() {

return list2;

}ADS_TO_REPLACE_21

public void setList2(String list2) {

this.list2 = list2;

}ADS_TO_REPLACE_22

public String getList3() {

return list3;

}ADS_TO_REPLACE_23

public void setList3(String list3) {

this.list3 = list3;

}ADS_TO_REPLACE_24

public String getList4() {

return list4;

}ADS_TO_REPLACE_25

public void setList4(String list4) {

this.list4 = list4;

}ADS_TO_REPLACE_26

public String display() {

return NONE;

}ADS_TO_REPLACE_27

public String getName() {

return name;

}ADS_TO_REPLACE_28

public void setName(String name) {

this.name = name;

}ADS_TO_REPLACE_29

}

4_struts.xml

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />ADS_TO_REPLACE_30

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

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

<action name="DoubleSelectTag" class="roseindia.DoubleSelectTag"ADS_TO_REPLACE_31

method="display">

<result name="none">/DoubleSelectTag.jsp</result>

</action>ADS_TO_REPLACE_32

<action name="DoubleSelectResult" class="roseindia.DoubleSelectTag">

<result name="success">/result.jsp</result>

</action>ADS_TO_REPLACE_33

</package>

</struts>

5_result.jsp

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

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">ADS_TO_REPLACE_35

<title>DoubleSelect Tag Example</title>

</head>

<body>Welcome Dear <s:property value="name"/><br>ADS_TO_REPLACE_36

Your Qualification is : <s:property value="list2"/><br>

Your Experience is : <s:property value="list4"/>

</body>ADS_TO_REPLACE_37

</html>

ADS_TO_REPLACE_38

Download Select Source Code


Related Tags for Struts2.2.1 doubleselect tag example.:

Advertisements

Ads

 
Advertisement null

Ads