Updownselect tag in Struts2 framework
Previous | Home | Next |
The struts2 framework provide updownselect component to select list option to change position of selected item up , down and select all item and then submit.The <s:updownselect></s:updownselect> tag provided by struts 2.0 tag library to select item and change position up and down or select all item.The updownselect component provide to select item and change position up and down or select all item which are following:<s:updownselect list="#{'Mukund':'Mukund', 'Harsh':'Harsh', 'Somaru':'Somaru','Gaurav':'Gaurav', 'Sushant':'Sushant'}" name="name" headerKey="-1" headerValue="--- Please Select Name ---" size="7"/>
Directory Structure of <s:updownselect> tag Example in Struts 2.0 Using MyEclipse IDEindex.jsp<%@taglib uri="/struts-tags" prefix="s" %> <h1>Updownselect tag example in Struts2 framework</h1> <s:form action="updown" method="POST" > <s:updownselect list="#{'Mukund':'Mukund', 'Harsh':'Harsh', 'Somaru':'Somaru','Gaurav':'Gaurav', 'Sushant':'Sushant'}" name="name" headerKey="-1" headerValue="--- Please Select Name ---" size="7"/> <s:updownselect list="courseList" name="course" headerKey="-1" headerValue="--- Please Select Course ---" size="10" moveUpLabel="Move Up" moveDownLabel="Move Down" selectAllLabel="Select All" /> <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.UpdownSelectAction" method="display"> <result name="none" type="dispatcher">/index.jsp</result> </action> <action name="updown" class="org.r4r.UpdownSelectAction"> <result name="success">/success.jsp</result> </action> </package> </struts>MyAction.javapackage org.r4r;
import java.util.ArrayList; import java.util.List; public class UpdownSelectAction { String name; String course; List<String> courseList; public UpdownSelectAction(){ courseList=new ArrayList<String>(); courseList.add("MCA"); courseList.add("MBA"); courseList.add("BCA"); courseList.add("BBA"); courseList.add("PGDM"); } public String execute(){ return "success"; } public String display(){ return "none"; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCourse() { return course; } public void setCourse(String course) { this.course = course; } public List<String> getCourseList() { return courseList; } public void setCourseList(List<String> courseList) { this.courseList = courseList; } }success.jsp<%@taglib uri="/struts-tags" prefix="s" %> <h1>Updownselect tag example in Struts2 framework</h1> Selected Name:-<s:property value="name"/><br/> Selected Course:-<s:property value="course"/>Output
Previous | Home | Next |