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 sidepublic 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;
}
}
}
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.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
for(int i=0;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
This comment has been removed by the author.
ReplyDeletedo you post information for non-java & non-gwt users. I am very much interested in learning from scratch.
ReplyDeleteHello, I гead youг blog lіkе eѵеry
ReplyDeletewееk. Υour ωriting style is witty, keep it
uρ!
Feel free tо visіt my site :: Windows 8 Loader By KMSpico
Hi, Neat post. There is an issue with your site in internet explorer,
ReplyDeletemay 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
I'm now not certain where you're getting your
ReplyDeleteinfo, 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
This post is invaluable. Where can I find out more?
ReplyDeleteReview my web blog :: vuelos a china
You have made some good points there. I checked on the
ReplyDeleteinternet 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
What's up, just wanted to say, I enjoyed this blog post.
ReplyDeleteIt was helpful. Keep on posting!
Here is my weblog - seo - seofornown4eva.com,
I couldn't resist commenting. Exceptionally well written!
ReplyDeleteFeel free to visit my blog :: Versace Scarves
After exploring a number of the blog articles on your site, I seriously appreciate
ReplyDeleteyoir 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
Heya i am for the primary time here. I found this board and I in finding
ReplyDeleteIt 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
I visited various web pages however the audio quality for audio songs current at this site is
ReplyDeletetruly excellent.
My web blog ... Christian Louboutin Heels
I was able to find good info from your articles.
ReplyDeletemy blog; Christian Louboutin Pumps
Superb, what a weblog it is! This webpage provides useful data to us, keep it
ReplyDeleteup.
Here is my web-site gta 5 cheat give weapons
I'm impressed, I have to admit. Rarely do I come across a blog that's equally educative and entertaining,
ReplyDeleteand 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
Excellent blog right here! Also your website rather a lot up
ReplyDeletevery 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
Excellent post! We will be linking to this particularly great article on our website.
ReplyDeleteKeep up the great writing.
Also visit my web site ... high school story cheat for android
I do trust all of the concepts you have offered in your post.
ReplyDeleteThey 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
Thank you for the good writeup. It in fact
ReplyDeletewas 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
I am genuinely thankful to the owner of this site who has
ReplyDeleteshared this impressive post at at this time.
Review my web page ... Friv2 Games Online
Appreciate the recommendation. Will try it out.
ReplyDeleteAlso visit my blog ... gta 5 6 milliarden cheat
Greetings from Ohio! I'm bored at work so I decided to
ReplyDeletecheck 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
I used to be recommended this blog by way of my cousin. I am no
ReplyDeletelonger 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
Great post. I used to be checking constantly this blog
ReplyDeleteand 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
Right here is the right blog for anyone who hopes to understand this topic.
ReplyDeleteYou 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
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.
ReplyDeleteIs there any way you can remove me from that service?
Thanks a lot!
Also visit my site; gta 5 cheat list
My family every time say that I am killing my time here
ReplyDeleteat web, however I know I am getting know-how every day by reading such
fastidious articles or reviews.
If some one desires to be upddated with newest technologies afterward he
ReplyDeletemust be visit this website and be up to date daily.