<action name="autocompleter" class="net.roseindia.autocompleter">
<result>/pages/autocompleter.jsp</result>
</action>
Create a list in the action class and populate
them with various states name of U.S. as shown in the "autocompleter"
class.
package net.roseindia;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
public class autocompleter extends ActionSupport{
private List state;
public String execute() throws Exception{
state = new ArrayList();
state.add("Alabama");
state.add("Alaska");
state.add("Arizona");
state.add("Arkansas");
state.add("California");
state.add("Colorado");
state.add("Connecticut");
state.add("Delaware");
state.add("District of Columbia");
state.add("Florida");
state.add("Georgia");
state.add("Hawaii");
state.add("Idaho");
state.add("Illinois");
state.add("Indiana");
state.add("Iowa");
state.add("Kansas");
state.add("Kentucky");
state.add("Louisiana");
state.add("Maine");
state.add("Maryland");
state.add("Massachusetts");
state.add("Michigan");
state.add("Minnesota");
state.add("Mississippi");
state.add("Missouri");
state.add("Montana");
state.add("Nebraska");
state.add("Nevada");
state.add("New Hampshire");
state.add("New Jersey");
state.add("New Mexico");
state.add("New York");
state.add("North Carolina");
state.add("North Dakota");
state.add("Ohio");
state.add("Oklahoma");
state.add("Oregon");
state.add("Pennsylvania");
state.add("Rhode Island");
state.add("South Carolina");
state.add("South Dakota");
state.add("Tennessee");
state.add("Texas");
state.add("Utah");
state.add("Vermont");
state.add("Virginia");
state.add("Washington");
state.add("West Virginia");
state.add("Wisconsin");
state.add("Wyoming");
return SUCCESS;
}
public List getState(){
return state;
}
}
|
<s:autocompleter theme="simple" list="state" StateName/>
it creates a autocompleter list with the name of U.S. sates.
autocompleter.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Struts 2 Autocompleter Example!</title>
<s:head theme="ajax" />
</head>
<body>
<h1>Struts 2 Autocompleter Example!</h1>
<s:label name="stateName" value="Select State Name:" />
<s:autocompleter theme="simple" list="state" name="StateName"/>
</body>
</html>
|
Output of the autocompleter.jsp :
When you enter the 'c' letter in the textbox. You gets the following: