SuggestBox implementation

289 views
Skip to first unread message

Deepak Singh

unread,
Aug 25, 2012, 6:34:36 PM8/25/12
to google-we...@googlegroups.com
Hi,

I have thousands of key-value pairs in my database and i need to show the values in a suggestBox. 
when the suggestion is selected, i should be able to get the key of selected value.

I dont want to load all the data on client machine. So what could be the best possible way to implement it ?

Thanks
Deepak Singh

Jens

unread,
Aug 25, 2012, 7:12:39 PM8/25/12
to google-we...@googlegroups.com
Create a small class that contains key/value and implements Suggestion and then create a custom SuggestOracle for your SuggestBox to fetch suggestions from your server based on the search string. 

-- J.

Deepak Singh

unread,
Aug 26, 2012, 12:36:11 PM8/26/12
to google-we...@googlegroups.com
But after selecting a value, how do i get the id of the selected value?

On Sun, Aug 26, 2012 at 4:42 AM, Jens <jens.ne...@gmail.com> wrote:
Create a small class that contains key/value and implements Suggestion and then create a custom SuggestOracle for your SuggestBox to fetch suggestions from your server based on the search string. 

-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/y9iQoBYKOawJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
Deepak Singh

Jens

unread,
Aug 26, 2012, 1:28:50 PM8/26/12
to google-we...@googlegroups.com
In your selection handler you have to cast the selected suggestion to your custom class.

-- J.

Thomas Broyer

unread,
Aug 26, 2012, 1:48:32 PM8/26/12
to google-we...@googlegroups.com


On Sunday, August 26, 2012 6:36:11 PM UTC+2, Deepak Singh wrote:
But after selecting a value, how do i get the id of the selected value?

SuggestBox works best if you use the ID as the "replacementString" and the label as the "displayString" of the Suggestions in your SuggestOracle. In that case, you don't have to do anything, the ID will be set in the text box upon selecting a suggestion.
(e.g. the "replacement string" is an email address, and the display string also contains the full name, the oracle using both the full name and email address for providing suggestions)

Deepak Singh

unread,
Aug 26, 2012, 5:20:31 PM8/26/12
to google-we...@googlegroups.com
Hi,

I tried this way

public class CustomSuggestion implements Suggestion{
public CityNameDTO dto = null;
public CustomSuggestion(CityNameDTO dto) {
this.dto = dto;
}
@Override
public String getDisplayString() {
return dto.getCityName();
}

@Override
public String getReplacementString() {
return dto.getCityId();
}

}


public class CustomSuggestOracle extends SuggestOracle{

List<CustomSuggestion> citySugggestions = null;
@Override
public void requestSuggestions(Request request, Callback callback) {
Response response  = new Response(getMatchingCities(request.getQuery(), request.getLimit()));
}
private List<CustomSuggestion> getMatchingCities(String query, int limit) {
List<CustomSuggestion> list = new ArrayList<CustomSuggestion>();
}
}


Now i am not able to understand how to go ahead with this customSuggestOracle.

Could you pls guide me here?

Thanks
Deepak

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
Deepak Singh

Ümit Seren

unread,
Aug 27, 2012, 3:12:38 AM8/27/12
to google-we...@googlegroups.com
It depends how you want to access your backend. Assuming you do a normal Ajax call you could do something like this:

private List<CustomSuggestion> getMatchingCities(String query, int limit) {
List<CustomSuggestion> list = new ArrayList<CustomSuggestion>();
        RequestBuilder request = new RequestBuilder(RequestBuilder.GET,url+"?query="+query+"&limit=" + limit);
request.setCallback(new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
//parse the result (maybe JSON) and populate your ArrayList
}
@Override
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
}
});
try
{
request.send();
}
catch (Exception e) {
To unsubscribe from this group, send email to google-web-toolkit+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
Deepak Singh

Deepak Singh

unread,
Aug 27, 2012, 10:49:57 AM8/27/12
to google-we...@googlegroups.com
I understand this. But my question is how do i implement CustomSuggestOracle.java

What will be implementation of the method getMatchingCities() in customSuggestionOracle ?

Thanks
Deepak 

To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/cGP5gBfv5soJ.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
Deepak Singh

Ümit Seren

unread,
Aug 27, 2012, 10:56:09 AM8/27/12
to google-we...@googlegroups.com
it depends how you access your backend? How do you transmit your DTO's
from the backend to the frontend?
Manually parsing JSON? RequestFactory? RPC?
>>>> google-web-tool...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/google-web-toolkit?hl=en.
>>>
>>>
>>>
>>>
>>> --
>>> Deepak Singh
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google Web Toolkit" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/google-web-toolkit/-/cGP5gBfv5soJ.
>>
>> To post to this group, send email to google-we...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> google-web-tool...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>
>
>
> --
> Deepak Singh
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.

Deepak Singh

unread,
Aug 27, 2012, 2:50:15 PM8/27/12
to google-we...@googlegroups.com
I would be using RPC and returning the List<DTO>.

Then how should i go ahead for implementation of CustomSuggestOracle ?
--
Deepak Singh

Ümit Seren

unread,
Aug 28, 2012, 3:56:28 AM8/28/12
to google-we...@googlegroups.com
public class CustomSuggestOracle extends SuggestOracle{

List<CustomSuggestion> citySugggestions = null;

@Override
public void requestSuggestions(Request request, Callback callback) {

Response response = new
Response(getMatchingCities(request.getQuery(), request.getLimit()));
callback.onSuggestionsReady(request,response);
}

private List<CustomSuggestion> getMatchingCities(String query, int limit) {

List<CustomSuggestion> list = new ArrayList<CustomSuggestion>();
//get List of suggested from the backend with RPC

}
}

And when you create the SuggestBox you pass your CustomSuggestOracle
as a constructor parameter
Reply all
Reply to author
Forward
0 new messages