PDA

View Full Version : Autocomplete ComboBox



bigmountainben
1 May 2009, 9:57 AM
Hi,

I am trying to write an autocomplete combo box for retrieving users. I am have some basic questions:

I have a serializable bean I use for User (User.class) which has a BeanModel UserBeanModel, with the @BeanModelMarker.BEAN(User.class) scheme.

I use a combination of the RpcProxy, BeanModelReader and BasePagingLoadConfig/BasePagingLoadResult.

My questions are:

1. On the server side I have a call that looks like this:

BasePagingLoadResult<User> getUsers(BasePagingLoadConfig config);

How do I specify the filtering info (i.e. what the user has typed) on config? It doesn't seem to get passed at all. If I have that I can return the offset easily and we'd be fine.

2. Can I do all this on the client? Ideally I'd like to download all the users, and do the filtering on the client. Is there a pattern to do this with ComboBox/Store/etc?

This is my (obviously incorrect) code:
<code>
public UserAutocompleteWidget() {
DataReader reader = new BeanModelReader<PagingLoadResult<User>>();
RpcProxy<BasePagingLoadConfig, BasePagingLoadResult<User>> proxy = new RpcProxy<BasePagingLoadConfig, BasePagingLoadResult<User>>() {
protected void load(BasePagingLoadConfig loadConfig, AsyncCallback<BasePagingLoadResult<User>> callback) {
UserService.App.getInstance().getUsers(loadConfig, callback);
}
};
PagingLoader<BasePagingLoadConfig> loader = new BasePagingLoader<BasePagingLoadConfig, BasePagingLoadResult<User>>(proxy,reader);

final ListStore<BeanModel> store = new ListStore<BeanModel>(loader);

loader.load();
setLoadingText("Loooking up users...");
setQueryDelay(100);
setMinChars(1);
setFieldLabel("Who");
setDisplayField("replacementString");
setStore(store);
setHideTrigger(true);
setPageSize(10);
}
</code>

Cheers!
Ben

bigmountainben
1 May 2009, 2:49 PM
Since I couldn't figure it out, I reverted back to using the standard GWT SuggestBox. As an aside, the whole ModelData/BeanModel API, while powerful and very versatile (and I haven't come close to really understand it fully), it's pretty damn complicated.

The SuggestBox API by contrast is easy to use and pretty elegant, though obviously much less general.

Just my 2 ems.

Ben