gwt suggestbox.

180 views
Skip to first unread message

kss

unread,
Oct 28, 2009, 4:46:03 PM10/28/09
to Google Web Toolkit
I am using the gwt suggestbox currently as a typeahead text box to
display suggestions from MultiSuggestOracle. Now I need a way to
enable the suggestbox to appear only after a fixed set of characters
are entered in the text box. Is there a way to do this ? Any
suggestions.

Thomas Broyer

unread,
Oct 29, 2009, 5:27:20 AM10/29/09
to Google Web Toolkit
Have your SuggestOracle return an empty response until the query is
"long enough" ?

Isaac Truett

unread,
Oct 29, 2009, 9:47:34 AM10/29/09
to google-we...@googlegroups.com
As Thomas said, you'll need to write a SuggestOracle that returns an
empty list of suggestions for queries shorter than x characters. And I
wanted to add: if you want to keep the functionality of the
MultiWordSuggestOracle then you can have your oracle delegate to a
MuliWordSuggestOracle instance for queries that are long enough. As I
recall MultiWordSuggestOracle is not amenable to subclassing, and
composition is a better strategy anyway.

mdwarne

unread,
Oct 29, 2009, 5:11:22 PM10/29/09
to Google Web Toolkit
I don't know if this helps, but I wrote a PersonSugggestOracle that
extends SuggestOracle

The method below calls the server. It doesn't call the server if
there are not at least 2 characters typed.

On the server side, I have a sql query that uses the characters to
perform a 'like' comparison on the first name, or the lastname so it
works similar to like a multiword suggest oracle.
On the server, I return the Person Name as a small HTML string with
<b></b> tags surround the characters that the user typed to emphasize
the part of the first or last name that is matching. I also limit the
response to 12 matching records on the server.

@Override
public void requestSuggestions(Request request, Callback callback)
{
nameCallback = callback;
String q = request.getQuery();
if (q >=2) {
asyncRequest.personSuggest(q,submitterId,12,new PersonsReceived
(request));
}
}

Mike.

kss

unread,
Nov 2, 2009, 3:24:22 PM11/2/09
to Google Web Toolkit
Thanks a lot. I followed the approach of extending SuggestOracle and
delegating the requestSuggestions to MultiWordSuggestOracle. It seems
to be working fine.

On Oct 29, 8:47 am, Isaac Truett <itru...@gmail.com> wrote:
> As Thomas said, you'll need to write a SuggestOracle that returns an
> empty list of suggestions for queries shorter than x characters. And I
> wanted to add: if you want to keep the functionality of the
> MultiWordSuggestOracle then you can have your oracle delegate to a
> MuliWordSuggestOracle instance for queries that are long enough. As I
> recall MultiWordSuggestOracle is not amenable to subclassing, and
> composition is a better strategy anyway.
>
> On Thu, Oct 29, 2009 at 5:27 AM, Thomas Broyer <t.bro...@gmail.com> wrote:
>
> > On 28 oct, 21:46, kss <kunjals...@gmail.com> wrote:
> >> I am using the gwtsuggestboxcurrently as a typeahead text box to
> >> display suggestions from MultiSuggestOracle. Now I need a way to
> >> enable thesuggestboxto appear only after a fixed set of characters

Jan Vladimir Mostert

unread,
Nov 22, 2012, 12:03:57 AM11/22/12
to google-we...@googlegroups.com
Hi, sorry for re-opening a topic from 2009.

In the above code, you said nameCallback = callBack, where is this nameCallback being used?
I don't quite understand how to use the callback.

I was just wondering if there's a full implementation / example available on how to extend the SuggestOracle using RPC.

public class MySuggestOracle extends SuggestOracle {

    @Override

    public void requestSuggestions(Request request, Callback callback) {

    }

}


// in my ManageSomePageView.java

TextBox textBox = new TextBox();

horizontalPanel.add(new SuggestBox(new MySuggestOracle(), textBox));



Thanks
Jan

Thomas Broyer

unread,
Nov 22, 2012, 3:53:47 AM11/22/12
to google-we...@googlegroups.com


On Thursday, November 22, 2012 6:03:57 AM UTC+1, Jan Vladimir Mostert wrote:
Hi, sorry for re-opening a topic from 2009.

In the above code, you said nameCallback = callBack, where is this nameCallback being used?
I don't quite understand how to use the callback.

I was just wondering if there's a full implementation / example available on how to extend the SuggestOracle using RPC.


Jan Vladimir Mostert

unread,
Nov 24, 2012, 2:06:15 PM11/24/12
to google-we...@googlegroups.com

Spent some time on it today and got it working, thanks Thomas!!

public class PietSuggestOracle extends SuggestOracle {

public static class PietSuggestion implements SuggestOracle.Suggestion {
private String displayString = "";
private String replacementString = "";
public PietSuggestion(String displayString, String replacementString){
this.displayString = displayString;
this.replacementString = replacementString;
}
@Override
public String getDisplayString() {
return this.displayString;
}

@Override
public String getReplacementString() {
return this.replacementString;
}
}
@Override
public void requestSuggestions(final Request request, final Callback callback) {
LinkedList<PietSuggestion> suggestions = new LinkedList<PietSuggestOracle.PietSuggestion>();
PietSuggestion suggestion1 = new PietSuggestion("TEST1", "TEST1");
suggestions.add(suggestion1);
PietSuggestion suggestion2 = new PietSuggestion("TEST2", "TEST2");
suggestions.add(suggestion2);
PietSuggestion suggestion3 = new PietSuggestion("TEST3", "TEST3");
suggestions.add(suggestion3);
Response response = new Response(suggestions);        
callback.onSuggestionsReady(request, response);
Reply all
Reply to author
Forward
0 new messages