SuggestBox implementation

289 visualitzacions
Ves al primer missatge no llegit

Deepak Singh

no llegida,
25 d’ag. 2012, 18:34:3625/8/12
a 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

no llegida,
25 d’ag. 2012, 19:12:3925/8/12
a 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

no llegida,
26 d’ag. 2012, 12:36:1126/8/12
a 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

no llegida,
26 d’ag. 2012, 13:28:5026/8/12
a google-we...@googlegroups.com
In your selection handler you have to cast the selected suggestion to your custom class.

-- J.

Thomas Broyer

no llegida,
26 d’ag. 2012, 13:48:3226/8/12
a 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

no llegida,
26 d’ag. 2012, 17:20:3126/8/12
a 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

no llegida,
27 d’ag. 2012, 3:12:3827/8/12
a 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

no llegida,
27 d’ag. 2012, 10:49:5727/8/12
a 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

no llegida,
27 d’ag. 2012, 10:56:0927/8/12
a 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

no llegida,
27 d’ag. 2012, 14:50:1527/8/12
a 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

no llegida,
28 d’ag. 2012, 3:56:2828/8/12
a 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
Respon a tots
Respon a l'autor
Reenvia
0 missatges nous