Pages

Monday, March 23, 2009

Gwt Suggest Box And Rpc

Share it Please
Gwt Suggest Box :

Hi Every One ,

This is my first blog .so please bare me if i need changes.

so what iam going to give you is a code on suggest box , how to make a callback to server for obtaining the suggestions using Suggest.Response and Request

so first let me create the files that are necessary .

On Client Side :

1. a suggestService which extends Remote Service

public interface SuggestService extends RemoteService {
public SuggestOracle.Response getSuggestions(SuggestOracle.Request req);

public static class Util {
public static SuggestServiceAsync getInstance(){
SuggestServiceAsync suggestService= (SuggestServiceAsync)GWT.create(SuggestService.class);
((ServiceDefTarget)suggestService).setServiceEntryPoint(GWT.getModuleBaseURL()+"/suggestions");
return suggestService;
}
}
}


2.an interface for AsyncCallback

public interface SuggestServiceAsync {
public void getSuggestions(SuggestOracle.Request req,AsyncCallback callback);
}


3.a suggestionClass which implements IsSerializable and Suggestion where this will be usefull in obtaining the suggestion supplied from server

public class Suggestions implements IsSerializable, Suggestion
{
private String suggestions; public String getDisplayString() {
return suggestions;
}

public String getReplacementString() {
return suggestions;
}

public Suggestions() { } //Constructor With Suggestion

public Suggestions(String suggestion) {
this.suggestions=suggestion;
}

}

4. The main important class is SuggestionOracle class which extends SuggestOracle .suggestOracle is used to create suggestions associated with a specific query string

public class SuggestionOracle extends SuggestOracle {

public void requestSuggestions(SuggestOracle.Request req,SuggestOracle.Callback callback) {
SuggestService.Util.getInstance().getSuggestions(req,new ItemRequestCallback(req,callback));
}

public boolean isDisplayStringHTML() {
return true;
}

public class ItemRequestCallback implements AsyncCallback{
private SuggestOracle.Request req;
private SuggestOracle.Callback callback;


public void onFailure(Throwable caught) {
callback.onSuggestionsReady(req,new SuggestOracle.Response()); caught.printStackTrace();
}

public void onSuccess(Object result) {
callback.onSuggestionsReady(req,(SuggestOracle.Response) result);
}

public ItemRequestCallback(SuggestOracle.Request _req,SuggestOracle.Callback _callback) {
this.req=_req; this.callback=_callback;
}
}
}

we have written all the files that are necessary on the client side.now we will move to server side

1. a class that implements The SuggestService and extends the RemoteServiceServlet

public class SuggestServiceImpl extends RemoteServiceServlet implements
SuggestService {

public Response getSuggestions(Request req) {

SuggestOracle.Response response=new SuggestOracle.Response();

ArrayList oracle=new ArrayList();
oracle.add("Afghanistan");
oracle.add("Albania");
oracle.add("Algeria");
oracle.add("American Samoa");
oracle.add("Andorra");
oracle.add("Angola");
oracle.add("Anguilla");
oracle.add("Antarctica");
oracle.add("Antigua And Barbuda");
oracle.add("Argentina");
oracle.add("Belgium");
oracle.add("Belize");
oracle.add("China");
oracle.add("Christmas Island");
oracle.add("Cocos (Keeling) Islands");
oracle.add("Colombia");
oracle.add("Comoros");
oracle.add("Congo, The Democratic Republic Of The");
oracle.add("Gabon");
oracle.add("Gambia");
oracle.add("Georgia");
oracle.add("Germany");
oracle.add("Ghana");

List mySuggestions = new ArrayList();

for(int i=0;i
<oracle.size();i++){
mySuggestions.add(oracle.get(i).toString());
}

response.setSuggestions(mySuggestions);
return response;
}
}




now from your OnModuleLoad() , call as

OnModuleLoad(){

SuggestionOracle oracle=new SuggestionOracle();
SuggestBox box=new SuggestBox(oracle,new MultipleTextBox());
box.setWidth("300px");
HorizontalPanel hPanel=new HorizontalPanel();
hPanel.add(new Label("Suggest Box"));
hPanel.add(box);
RootPanel.get().add(hPanel);

}



u can check the Image for Demonstration





















In My Next Article We Will see how to Create a suggest box which works similarly like the Gmail's "To" Field


28 comments :

  1. This comment has been removed by the author.

    ReplyDelete
  2. do you post information for non-java & non-gwt users. I am very much interested in learning from scratch.

    ReplyDelete
  3. Hello, I гead youг blog lіkе eѵеry
    wееk. Υour ωriting style is witty, keep it
    uρ!

    Feel free tо visіt my site :: Windows 8 Loader By KMSpico

    ReplyDelete
  4. Hi, Neat post. There is an issue with your site in internet explorer,
    may check this? IE still is the market leader and a big section of other folks will pass over your great
    writing due to this problem.

    my web page ... Christian Louboutin Outlet

    ReplyDelete
  5. I'm now not certain where you're getting your
    info, however good topic. I needs to spend a while
    learning much more or working out more. Thank you for fantastic
    information I used to be looking for this information for my
    mission. web design company kerala
    Also visit my webpage ; web design company kerala

    ReplyDelete
  6. This post is invaluable. Where can I find out more?
    Review my web blog :: vuelos a china

    ReplyDelete
  7. You have made some good points there. I checked on the
    internet to find out more about the issue and found most individuals
    will go along with your views on this site.

    my site ... GHD Hair Straightener

    ReplyDelete
  8. What's up, just wanted to say, I enjoyed this blog post.
    It was helpful. Keep on posting!

    Here is my weblog - seo - seofornown4eva.com,

    ReplyDelete
  9. I couldn't resist commenting. Exceptionally well written!

    Feel free to visit my blog :: Versace Scarves

    ReplyDelete
  10. After exploring a number of the blog articles on your site, I seriously appreciate
    yoir technique of writing a blog. I saved it to myy bookmark website list and will be checking back soon. Please check out my web site as well and tell me your opinion.

    Stop by my web page; imprese

    ReplyDelete
  11. Heya i am for the primary time here. I found this board and I in finding
    It really helpful & it helped me out much. I hope to offer something back and
    aid others such as you aided me.

    Feel free to surf to my homepage: Christian Louboutin Wedding Shoes

    ReplyDelete
  12. I visited various web pages however the audio quality for audio songs current at this site is
    truly excellent.

    My web blog ... Christian Louboutin Heels

    ReplyDelete
  13. I was able to find good info from your articles.



    my blog; Christian Louboutin Pumps

    ReplyDelete
  14. Superb, what a weblog it is! This webpage provides useful data to us, keep it
    up.

    Here is my web-site gta 5 cheat give weapons

    ReplyDelete
  15. I'm impressed, I have to admit. Rarely do I come across a blog that's equally educative and entertaining,
    and without a doubt, you have hit the nail on the head.
    The problem is something too few people are speaking intelligently about.
    Now i'm very happy I found this during my hunt for something relating
    to this.

    My web-site - fable the lost chapters age hack

    ReplyDelete
  16. Excellent blog right here! Also your website rather a lot up
    very fast! What web host are you the usage of? Can I am getting
    your affiliate hyperlink on your host? I wish my web
    site loaded up as fast as yours lol

    Look into my website clash of clans gem generator

    ReplyDelete
  17. Excellent post! We will be linking to this particularly great article on our website.
    Keep up the great writing.

    Also visit my web site ... high school story cheat for android

    ReplyDelete
  18. I do trust all of the concepts you have offered in your post.
    They are really convincing and can certainly work. Still, the posts are very quick for newbies.
    May you please extend them a little from next time? Thank you for the
    post.

    My weblog - gta 5 cheats questions

    ReplyDelete
  19. Thank you for the good writeup. It in fact
    was a amusement account it. Look advanced to far added agreeable
    from you! By the way, how can we communicate?

    my blog :: clash of clans multiplayer

    ReplyDelete
  20. I am genuinely thankful to the owner of this site who has
    shared this impressive post at at this time.



    Review my web page ... Friv2 Games Online

    ReplyDelete
  21. Appreciate the recommendation. Will try it out.


    Also visit my blog ... gta 5 6 milliarden cheat

    ReplyDelete
  22. Greetings from Ohio! I'm bored at work so I decided to
    check out your blog on my iphone during lunch break.
    I love the information you present here and can't wait to take a
    look when I get home. I'm amazed at how fast your blog loaded on my cell phone ..
    I'm not even using WIFI, just 3G .. Anyways, great site!



    Here is my page: Running Shoes

    ReplyDelete
  23. I used to be recommended this blog by way of my cousin. I am no
    longer positive whether this submit is written by way of him as nobody else
    recognise such distinctive about my problem. You're amazing!
    Thanks!

    My web blog; New Balance Store

    ReplyDelete
  24. Great post. I used to be checking constantly this blog
    and I am impressed! Very useful information specially the remaining section :
    ) I handle such information a lot. I used to be looking for this certain info for a long time.
    Thanks and best of luck.

    My website - New Balance Minimus

    ReplyDelete
  25. Right here is the right blog for anyone who hopes to understand this topic.
    You know so much its almost hard to argue with you
    (not that I really would want to…HaHa). You certainly put a fresh spin on a subject which has
    been written about for decades. Excellent stuff, just wonderful!


    Also visit my webpage - bp claims

    ReplyDelete
  26. When I originally commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I get several e-mails with the same comment.
    Is there any way you can remove me from that service?
    Thanks a lot!

    Also visit my site; gta 5 cheat list

    ReplyDelete
  27. My family every time say that I am killing my time here
    at web, however I know I am getting know-how every day by reading such
    fastidious articles or reviews.

    ReplyDelete
  28. If some one desires to be upddated with newest technologies afterward he
    must be visit this website and be up to date daily.

    ReplyDelete