Home Tutorials Gwt Building Suggestion Box Using GWT
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Building Suggestion Box Using GWT

Advertisement
This example describes the Basics for building the suggestion box using GWT.

Building Suggestion Box Using GWT

     

This example describes the Basics for building the suggestion box using GWT. The steps involved in Building the Suggestion box are described below:-
final Label label = new Label("Enter the text in Suggestion box")
Here we are declaring label.

MultiWordSuggestOracle oracle = new MultiWordSuggestOracle()
Here we are creating object of class MultiWordSuggestOracle .MultiWordSuggestOracle  is a class that returns suggestion based on the query.

oracle. add("Cat")
This methods adds a suggestion to the oracle.

Suggest Box box = new SuggestBox(oracle)
Creating Suggest box , A suggest is a text area which displays a pre-configured set of selections.

RootPanel.get().add(label)
By this method we are adding label to the rootpanel.Root panel is a panel to which all other widgets must  be added. it is not created directly.

SuggestBoxex.java


package org.yournamehere.client;
import com.google.gwt.user.client.ui.Label; 
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SuggestBox;

public class SuggestBoxex {
  final Label label = new Label("Enter the text in Suggestion box");
 public void onModuleLoad() {
 MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();  
 oracle.add("Cat");
 oracle.add("Dog");
 oracle.add("Horse");
 oracle.add("india");
 oracle.add("Canada");
 oracle.add("France");
 oracle.add("uk");
 oracle.add("Japan");
 oracle.add("Russia");
 
 SuggestBox box = new SuggestBox(oracle);
 RootPanel.get().add(label);
 RootPanel.get().add(box);
  };
  
}

Main.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<module>
  <inherits name="com.google.gwt.user.User"/>
  <entry-point class="org.yournamehere.client.SuggestBoxex"/>
  
</module>

Output of the program

Download source code

     

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 6, 2008

Ask Questions?    Discuss: Building Suggestion Box Using GWT   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
alamin
September 2, 2012
how to get text,value pairs in gwt suggestionBox

i need a autosuggest combobox for an ambiguous list of strings. but everey string has an unique id. this id is needed to know what the user has selected (send id back to server and do something with it). how to implement this with the gwt's auto-suggest-comboBox "suggestionBox". Is there a way to get an List of id->name pairs (like with listBox.addItem(String name, String value)) into the suggestionBox? probably by overwriting suggestionOracle? (how to get the selected id of the selected name?) or is this usecase better be implemented by another gwt widget?
alamin
September 2, 2012
how to get text,value pairs in gwt suggestionBox

i need a autosuggest combobox for an ambiguous list of strings. but everey string has an unique id. this id is needed to know what the user has selected (send id back to server and do something with it). how to implement this with the gwt's auto-suggest-comboBox "suggestionBox". Is there a way to get an List of id->name pairs (like with listBox.addItem(String name, String value)) into the suggestionBox? probably by overwriting suggestionOracle? (how to get the selected id of the selected name?) or is this usecase better be implemented by another gwt widget?
DMCA.com