displaying all suggestions in a suggest box

471 views
Skip to first unread message

dandante

unread,
Feb 26, 2008, 5:27:28 PM2/26/08
to Google Web Toolkit
Hi,

I would like to use the suggest box in a slightly more combo-box like
manner: I would like to see ALL the suggestions displayed (there
aren't that many) if the user double-clicks in the box, or types * in
the box.

I know how to trap the double-click event, so I don't need to focus on
that. I looked at the code for the oracles and tried creating my own
and even tried copying/modifyng one of google's classes but I could
not figure out how to make a request that would return all
suggestions.

I looked into using the GWT-EXT combo box but that presented a whole
host of other problems....

Can anyone give me some suggestions (haha) for displaying all
suggestions?
Thanks

Michael Press

unread,
Feb 26, 2008, 6:35:39 PM2/26/08
to Google Web Toolkit
You can write your own SuggestOracle to do your own matching. Since
your SuggestOracle implementation returns whatever YOU say matches,
it could easily return everything if the search string is "*" or
whatever your magic phrase is.

I posted code to this forum a while back with my SuggestOracle
implementation -
http://groups.google.com/group/Google-Web-Toolkit/browse_frm/thread/349144a2fa934e5/a570493ea675d282?lnk=gst&q=SuggestOracle+press#a570493ea675d282

The requestSuggestions() implementation calls the GWT
callback.onSuggestionReady() with the suggestions to put in the
dropdown; instead of checking for matches and restricting to a limit
of 20 like I did, you could return all the items in the list.

I think GWT should have included a base implementation like this one
that requires only your own matching algorithm in the computeItemsFor
method().

Michael

dandante

unread,
Feb 26, 2008, 7:08:30 PM2/26/08
to Google Web Toolkit
Nice...I got it to work. BTW I also had to implement the method
getReplacementString() from SuggestOracle.Suggestion, but that was no
big deal.
I changed it so that if you type '*' in the box it displays all
suggestions...now I just need to make a double-click trigger a '*'
suggestion request.
Thanks!


On Feb 26, 3:35 pm, Michael Press <michaelpr...@gmail.com> wrote:
> You can write your own SuggestOracle to do your own matching. Since
> your SuggestOracle implementation returns whatever YOU say matches,
> it could easily return everything if the search string is "*" or
> whatever your magic phrase is.
>
> I posted code to this forum a while back with my SuggestOracle
> implementation -http://groups.google.com/group/Google-Web-Toolkit/browse_frm/thread/3...

dandante

unread,
Feb 26, 2008, 8:07:42 PM2/26/08
to Google Web Toolkit
Um....now I'm stuck trying to populate the suggest box suggestions in
response to an event.
I want it to be so that if you press Enter in the suggest box it
behaves as though you had typed '*' in it.

final StartsWithSuggestOracle oracle = new
StartsWithSuggestOracle();
oracle.add("Aa");
oracle.add("Bb");

final SuggestBox sb = new SuggestBox(oracle);

sb.addKeyboardListener(new KeyboardListenerAdapter(){
public void onKeyPress(Widget widget, char c, int i) {
super.onKeyPress(widget, c, i);
if (c == KeyboardListener.KEY_ENTER && i == 0) {
SuggestOracle.Request req = new
SuggestOracle.Request("*");
oracle.requestSuggestions(req, new
SuggestOracle.Callback() {
public void
onSuggestionsReady(SuggestOracle.Request request,
SuggestOracle.Response response) {
//i dunno
//sb.setText("*"); // this works but it's
kludgey. i'd rather do it another way
}
});
}
}
});

So I think I'm missing something somewhere...how do I trigger
SuggestBox to give me the same response it would give me had I typed
something in?
Thanks....
Reply all
Reply to author
Forward
0 new messages