Autocompleter tag in struts2 framework
Previous | Home | Next |
Struts2 framework provide Autocompleter component is a combo box which are auto prompt item add in the list then select and submitDownload the struts2-dojo-plugin.jar library and Include the “struts-dojo-tags” tag and output its header.The following tag support struts2 framework,<sx:autocompleter label="My Favorite Book" name="mybook" autoComplete="false" list="{'CoreJava','J2EE','JDBC','Struts1.3','Struts2.0','Spring','Hibernate','EJB', 'Collection','Servlet','JSP','RMI'}" />
Directory Structure of <sx:autocompleter> tag Example in Struts 2.0 Using MyEclipse IDEindex.jsp<%@ taglib prefix="s" uri="/struts-tags" %> <%@ taglib prefix="sx" uri="/struts-dojo-tags" %> <h1>Autocompleter Tag Example in Struts2 Framework</h1> <s:form action="auto" method="POST" > <sx:autocompleter label="My Favorite Book" name="mybook" autoComplete="false" list="{'CoreJava' , 'J2EE' , 'JDBC' , 'Struts1.3' , 'Struts2.0' , 'Spring' , 'Hibernate' , 'EJB' , 'Collection' , 'Servlet' , 'JSP' , 'RMI'}" /> <sx:autocompleter label="My Favorite Course" list="mycourses" name="course" /> <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.AutocompleterAction" method="display"> <result name="none" type="dispatcher">/index.jsp</result> </action> <action name="auto" class="org.r4r.AutocompleterAction"> <result name="success">/success.jsp</result> </action> </package> </struts>AutocompleterAction.javapackage org.r4r; import java.util.ArrayList; import java.util.List; public class AutocompleterAction { List<String> mycourses; String course; String mybook; public AutocompleterAction(){ mycourses=new ArrayList<String>(); mycourses.add("I.Sc."); mycourses.add("B.Sc."); mycourses.add("M.Sc."); mycourses.add("I.A."); mycourses.add("B.A."); mycourses.add("M.A."); mycourses.add("I.Com."); mycourses.add("B.Com."); mycourses.add("M.Com."); mycourses.add("MCA"); mycourses.add("MBA"); mycourses.add("BCA"); } public String execute(){ return "success"; } public String display(){ return "none"; } public List<String> getMycourses() { return mycourses; } public void setMycourses(List<String> mycourses) { this.mycourses = mycourses; } public String getCourse() { return course; } public void setCourse(String course) { this.course = course; } public String getMybook() { return mybook; } public void setMybook(String mybook) { this.mybook = mybook; } }success.jsp<%@ taglib prefix="s" uri="/struts-tags" %> <h1>Autocompleter Tag Example in Struts2 Framework</h1> <h4>My Favorite Book : <s:property value="mybook"/></h4> <h4>My Favorite Course : <s:property value="course"/></h4>Output
Previous | Home | Next |