Newsletter |
Using Struts 2 Autocompleter With Example
Struts » on Oct 29, 2011 { 6 Comments } By Sivateja
Let us see how to work with struts 2 autocompleter tag with example. This autocompleter tag will works asynchronously, and dont forget to add <s:head theme=”ajax” /> in the header part of the webpage [ check in success.jsp ].
jars required
- commons-logging-1.0.4.jar
- freemarker-2.3.8.jar
- ognl-2.6.11.jar
- struts2-core-2.0.11.jar
- xwork-2.0.4.jar
Example
files required
- index.jsp
- success.jsp
- web.xml
- struts.xml
- LogingEx.java
Directory Structure
index.jsp
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=iteAction.action">
success.jsp
<%@ taglib prefix="s" uri="/struts-tags" %> <head> <s:head theme="ajax" /> </head> <s:label value="Your State" /> <s:autocompleter theme="simple" list="states"/>
LogingEx.java
package java4s; import java.util.ArrayList; import java.util.List; import com.opensymphony.xwork2.ActionSupport; public class LogingEx extends ActionSupport{ private static final long serialVersionUID = 1L; private List states; public List getStates() { return states; } public String execute() throws Exception{ states = new ArrayList(); states.add("Alabama"); states.add("Alaska"); states.add("Arizona"); states.add("Arkansas"); states.add("California"); states.add("Colorado"); states.add("Connecticut"); states.add("Delaware"); states.add("District of Columbia"); states.add("Florida"); states.add("Georgia"); states.add("Hawaii"); states.add("Idaho"); states.add("Illinois"); states.add("Indiana"); states.add("Iowa"); states.add("Kansas"); states.add("Kentucky"); states.add("Louisiana"); states.add("Maine"); states.add("Maryland"); states.add("Massachusetts"); states.add("Michigan"); states.add("Minnesota"); states.add("Mississippi"); states.add("Missouri"); states.add("Montana"); states.add("Nebraska"); states.add("Nevada"); states.add("New Hampshire"); states.add("New Jersey"); states.add("New Mexico"); states.add("New York"); states.add("North Carolina"); states.add("North Dakota"); states.add("Ohio"); states.add("Oklahoma"); states.add("Oregon"); states.add("Pennsylvania"); states.add("Rhode Island"); states.add("South Carolina"); states.add("South Dakota"); states.add("Tennessee"); states.add("Texas"); states.add("Utah"); states.add("Vermont"); states.add("Virginia"); states.add("Washington"); states.add("West Virginia"); states.add("Wisconsin"); states.add("Wyoming"); return SUCCESS; } }
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
struts.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <include file="struts-default.xml"/> <package name="a" extends="struts-default"> <action name="iteAction" class="java4s.LogingEx"> <result name="success">/success.jsp</result> </action> </package> </struts>
Output
You Might Also Like
::. About the Author .:: | ||
Comments
6 Responses to “Using Struts 2 Autocompleter With Example”
I enjoy the efforts you have put in this, appreciate it for all the great posts.
while running it is showing that
No tag “autocompleter” defined in tag library imported with prefix “s”
while running it is showing that
No tag “autocompleter” defined in tag library imported with prefix “s”
what is the solution of this…?
I want to Dynamically add, remove rows on table and insert all rows values into Mysql database using Struts-2, so please help how to do this task
How to read the the selected data into another text box. Please help me regarding this.
Thanks in advance.
how to fill form onclick text other text field auto fill as per first??