The Struts-Layout Suggest tag allows to render a text field with a suggestions list: when a user types a character, the tag shows suggestions matching typed word, and the user just have to use keyboard or mouse in order to choose one of these suggestions.
Here are the required steps to create a suggest field:
This tutorial is based on the demo application named CountrySuggest, which shows an example of a suggest field allowing to type easily country names. Here is the result:

In fact, when a user types a character, a Struts action is called. This action class has two particularities:
package fr.improve.demosuggest.countries;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import fr.improve.struts.taglib.layout.suggest.SuggestAction;
public class CountrySuggestAction extends SuggestAction {
public Collection getSuggestionList(HttpServletRequest in_request, String in_word) {
// Get all the country names
Collection allCountries = CountryCollection.getAllCountries();
// Start to build the suggestions list
ArrayList suggestions = new ArrayList();
if (in_word != null && in_word.length() > 0)
{
Iterator iter = allCountries.iterator();
while(iter.hasNext())
{
String currentWord = (String) iter.next();
if(currentWord.toLowerCase().startsWith(in_word.toLowerCase()))
suggestions.add(currentWord);
}
}
return suggestions;
}
}
Note that this code is based on a class named CountryCollection providing a method called getAllCountries() returning all country names.
Just add these lines into your struts-config.xml file (in the <action-mappings> ... </action-mappings> part):
<struts-config> ... <action-mappings> <action path="/getCountrySuggestions" type="fr.improve.demosuggest.countries.CountrySuggestAction"> </action> </action-mappings> ... </struts-config>
Finally just add the <layout:suggest> tag into a JSP page:
<%@ taglib uri="/WEB-INF/struts-layout.tld" prefix="layout" %> <layout:html> <layout:suggest suggestAction="/getCountrySuggestions" key="Country" styleId="myTextField" value="" suggestCount="8" /> </layout:html>
Note that you can also specify the 'property' attribute in order to bound this field to a property of an action form.