In this section, we are going to describe the autocompleter tag. The autocompleter tag always displays a dropdown list with the options that have at least a partial match with entered text in the textbox. If the user clicks on the dropdown button then all options shown in the dropdown list. The autocompleter tag generates two input fields. First is "text", whose name is specified with the "name" attribute and another one is "hidden" whose name is "$(name). Key", where ${name} is the value in the "name" attribute.
The autocompleter tag loads its options asynchronously when the page loads suggested options based on the text entered by you in textbox. If the autoComplete attribute is set to 'true' (By defalut 'false') then it makes suggestions in the textbox.
[Note: When we use the "simple" theme, the autocompleter can be used like the ComboBox. When used on the "ajax" theme, the list can be retrieved from an action.]
Add the following code snippet into the struts.xml file.
| <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;
|
<s:autocompleter theme="simple" list="state" StateName/>
it creates a autocompleter list with the name of U.S. states.
autocompleter.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
|
Output of the autocompleter.jsp :
![]() |
When you enter the 'c' letter in the textbox. You get the following names:
![]() |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Auto Completer Example View All Comments
Post your Comment