Struts 2 <s:doubleselect> tag example

Struts 2 <s:doubleselect> tag example

Previous Home Next

 

The struts2 framework provide doubleselect component to select pair selection if one selection is depend on second selection.
The <s:doubleselect></s:doubleselect> tag provided by struts 2.0 tag library to select two item in same time.
The doubleselection component provide to choose two item which are following:
<s:doubleselect label="Alpha Bate " name="alphabate1" list="{'Character','Number'}" doubleName="alphabate2" doubleList="top == 'character' ? {'A', 'B','C','D'} : {'1', '2','3','4'}" />




 
Directory Structure of <s:doubleselect> tag Example in Struts 2.0 Using MyEclipse IDE



index.jsp

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

<h2>Double Select tag example in struts2 framework</h2>
<s:form action="double"> 
<s:doubleselect label="Data Type" 
name="datatype1" list="{'string','integer'}" 
doubleName="datatype2" 
doubleList="top == 'string' ? {'A', 'B','C'} : {'1', '2', '3'}" />
 
<s:set name="nameList" 
value="#{'BoysName': {'Mukund', 'Harsh', 'Somaru'},'GirlsName': {'Kavita', 'Sita','Radha'}}" />
<s:doubleselect label="Student" 
name="BoysName" list="#nameList.keySet()" doubleName="GirlsName" doubleList="#nameList[top]" />
<s:submit value="submit" name="submit" />
</s:form>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  
  <filter>
  <filter-name>f1</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>f1</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration
2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="demo" extends="struts-default">
<action name="" class="org.r4r.DoubleselectionAction" method="display">
<result name="none" type="dispatcher">/index.jsp</result>
</action>
<action name="double" class="org.r4r.DoubleselectionAction">
<result name="success">/success.jsp</result>
</action>
</package>
</struts> 

DoubleselectionAction.java

package org.r4r;


public class DoubleselectionAction {
	String datatype1;
	String datatype2;
	
	String BoysName;
	String GirlsName;
	
	public String execute(){
		return "success";
	}
	public String display(){
		return "none";
	}
	
	public String getDatatype1() {
		return datatype1;
	}
	public void setDatatype1(String datatype1) {
		this.datatype1 = datatype1;
	}
	public String getDatatype2() {
		return datatype2;
	}
	public void setDatatype2(String datatype2) {
		this.datatype2 = datatype2;
	}
	
	public String getBoysName() {
		return BoysName;
	}
	public void setBoysName(String boysName) {
		BoysName = boysName;
	}
	public String getGirlsName() {
		return GirlsName;
	}
	public void setGirlsName(String girlsName) {
		GirlsName = girlsName;
	}
	

}

success.jsp

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

Datatype:-<s:property value="datatype1"/>,
<s:property value="datatype2"/><br/>
Student Name:-<s:property value="BoysName"/>,
<s:property value="GirlsName"/>

Output






Previous Home Next