Services | Updates | Contact
Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
Search All Tutorials
Top Search: Loan Struts Open Source
Convert Liters To Gallons
In this section, you will learn to convert Liters To Gallons. The following program helps you in converting Liters To Ga
 
What is Solex ?
Solex is a free open source Web application testing tool built as a plug-in for the Eclipse IDE. It provides functions
 
More Tutorials...

Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

 
 
Struts
Comments
 
 

 

Auto Completer Example

                         

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;
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. states.

autocompleter.jsp

<%taglib prefix="s" uri="/struts-tags" %>

<html>
  <head>
    <title>Struts Autocompleter Example!</title>
    <s:head theme="ajax" />
  </head>
  <body>
    <h1>Struts 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 get the following names:

                         
Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

6 comments so far (post your own) View All Comments Latest 10 Comments:

Hi

I tried ur code , if i am passing list name in jsp auto complete is not working
If i put some hard coded values as list values it works

do suggest

Posted by Amit on Wednesday, 04.30.08 @ 09:58am | #58188

hi, how do i get the value from the selected autocompleter?

Posted by Tsai on Thursday, 01.3.08 @ 10:26am | #44417

Can it be drill down to 3 level like select state-> select ->Road ,Select - > House

Posted by sarkar on Monday, 11.5.07 @ 19:17pm | #35631

Can I to use Struts 1.2 this example?

Posted by Ande- on Friday, 09.28.07 @ 21:27pm | #30164


Hi Sagar,
The above example is developed using <s:head theme="ajax" /> tag.

Please check it again.

Thank you for visiting and reading our site.

Vinod Kumar

Posted by Vinod Kumar on Friday, 09.7.07 @ 16:32pm | #26306

can u send any example of <s:autocompleter> with theme="ajax" . Thank you

Posted by Sagar on Friday, 09.7.07 @ 15:46pm | #26303

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.