Optiontransferselect tag in Struts2 framework
Previous | Home | Next |
Struts2 framework provide Optiontransferselect component to transfer selected item left to right and also change position of item up or down.Struts2 tag library provide Optiontransferselect component to transfer item left to right and also change position up and down.<s:optiontransferselectlabel="Student Name" name="boysname" list="{'101 - Mukund ', '102 - Harsh', '103 - Somaru', '104 - Pramod', '105 - Sushant'}" doubleName="girlsname" doubleList="{'201 - Radha','202 - Rupam','203 - Ranjan','204 - Babita','205 - Kanchan'}" />
Directory Structure of <s:optiontransferselect> tag Example in Struts 2.0 Using MyEclipse IDEindex.jsp<%@taglib uri="/struts-tags" prefix="s"%> <h2>Optiontransferselect Tag Example in struts2 Framework</h2> <s:form action="option" method="POST" > <s:optiontransferselect label="Student Name" name="boysname" list="{'101 - Mukund ', '102 - Harsh', '103 - Somaru', '104 - Pramod', '105 - Sushant'}" doubleName="girlsname" doubleList="{'201 - Radha','202 - Rupam','203 - Ranjan','204 - Babita','205 - Kanchan'}" /> <s:optiontransferselect label="Teacher" name="maleteacher" leftTitle="Male Teacher" rightTitle="Female Teacher" list="maleTeacher" multiple="true" headerKey="-1" headerValue="--- Please Select ---" doubleList="femaleTeacher" doubleName="femaleteacher" doubleHeaderKey="-1" doubleHeaderValue="--- Please Select ---" /> <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.OpTranAction" method="display"> <result name="none" type="dispatcher">/index.jsp</result> </action> <action name="option" class="org.r4r.OpTranAction"> <result name="success">/success.jsp</result> </action> </package> </struts>OpTranAction.javapackage org.r4r; import java.util.ArrayList; import java.util.List; public class OpTranAction { List<String> maleTeacher; List<String> femaleTeacher; String maleteacher; String femaleteacher; String boysname; String girlsname; public OpTranAction(){ maleTeacher=new ArrayList<String>(); maleTeacher.add("M.K.Singh"); maleTeacher.add("B.M.Singh"); maleTeacher.add("R.K.Yadav"); maleTeacher.add("H.Vardhan"); maleTeacher.add("S.Ram"); femaleTeacher=new ArrayList<String>(); femaleTeacher.add("Ranjan Singh"); femaleTeacher.add("Kavita Dahima"); femaleTeacher.add("Subham"); femaleTeacher.add("Suman"); femaleTeacher.add("Kanchan Bala"); } public String execute(){ return "success"; } public String display(){ return "none"; } public List<String> getMaleTeacher() { return maleTeacher; } public void setMaleTeacher(List<String> maleTeacher) { this.maleTeacher = maleTeacher; } public List<String> getFemaleTeacher() { return femaleTeacher; } public void setFemaleTeacher(List<String> femaleTeacher) { this.femaleTeacher = femaleTeacher; } public String getMaleteacher() { return maleteacher; } public void setMaleteacher(String maleteacher) { this.maleteacher = maleteacher; } public String getFemaleteacher() { return femaleteacher; } public void setFemaleteacher(String femaleteacher) { this.femaleteacher = femaleteacher; } public String getBoysname() { return boysname; } public void setBoysname(String boysname) { this.boysname = boysname; } public String getGirlsname() { return girlsname; } public void setGirlsname(String girlsname) { this.girlsname = girlsname; } }success.jsp<%@taglib uri="/struts-tags" prefix="s"%> <h2>Optiontransferselect Tag Example in struts2 Framework</h2> <h4>Boys Name : <s:property value="boysname"/></h4> <h4>Girls Name : <s:property value="girlsname"/></h4> <h4>Male Teacher : <s:property value="maleteacher"/></h4> <h4>Female Teacher : <s:property value="femaleteacher"/></h4>Output
Previous | Home | Next |