PDA

View Full Version : SimpleComboBox, setting default value when using RPC store failes



Manuel1982
23 Jun 2010, 3:06 AM
Hi,
here a complete example:
While debugging I found out that on calling customerId.setValue(store2.getAt(1)); RcpProxy trows an exception and makes a callback.onFailure() but I don't where to add the proper Listener interface to get the onFailure callback.

What works -> The data fetched from the server is shown as expected if the customerId.setValue(store2.getAt(1)); is removed.

What doesn't work -> fetching a specific item from the store to set it as default



package com.rzsystems.vpp.client;

import java.util.List;

import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.form.SimpleComboValue;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;
import com.rzsystems.vpp.shared.entities.Customer;


public class TestEntryPoint implements EntryPoint {
private final ICustomerServiceAsync customerService = (ICustomerServiceAsync) GWT
.create(ICustomerService.class);
private ListStore<SimpleComboValue<BeanModel>> store2;
private SimpleComboBox<BeanModel> customerId = new SimpleComboBox<BeanModel>();

public void onModuleLoad() {
RpcProxy<List<Customer>> proxy2 = new RpcProxy<List<Customer>>() {
@Override
public void load(Object loadConfig, AsyncCallback<List<Customer>> callback) {
customerService.getCustomers(callback);
}
};

BeanModelReader reader2 = new BeanModelReader();

final ListLoader loader2 = new BaseListLoader<ListLoadResult<Customer>>(proxy2, reader2);
store2 = new ListStore<SimpleComboValue<BeanModel>>(loader2);
loader2.load();
loader2.addListener(ListLoader.Load, new Listener<BaseEvent>() {

@Override
public void handleEvent(BaseEvent be) {
// TODO Auto-generated method stub
Info.display("Finished Loading", "Finished loading.");
customerId.setValue(store2.getAt(1));
}
});

customerId.setName("customer_id");
customerId.setFieldLabel("Kunde");
customerId.setStore(store2);
customerId.setAllowBlank(false);
customerId.setEditable(false);
customerId.setLazyRender(false);
customerId.setEnabled(false);
customerId.setTriggerAction(TriggerAction.ALL);
customerId.setDisplayField("customerName");

RootPanel.get().add(customerId);

}

}

sven
23 Jun 2010, 8:27 AM
So what is the exception you are getting?

Manuel1982
24 Jun 2010, 1:40 AM
It didn't throw, but caught the exception, so I couldn't tell the exact exception, because I had no onFailure / onSuccess implementation and I forgot to take a look at the exception while debugging...yesterday was not a good day.

But I found a simple solution with ComboBox:
I removed the proxy, loader and reader stuff since I do not need them. Now I simply add the result of my async call to the combobox store and voilá.