PDA

View Full Version : DualListField Problem



ishak1981
12 Dec 2010, 6:15 AM
Hello everybody

i habe a problem with the store of toListField. After i added a StoreListener to the store of toListField , the item is still visible in the toListField, when i drag and drop this item from toListField to fromListField. I want to access to the Models in the Listener. The code from EntryPoint:
FormPanel panel = new FormPanel();
panel.setFrame(true);
panel.setHeading("DualListField Example");

TextField<String> name = new TextField<String>();
name.setFieldLabel("Name");
panel.add(name, new FormData("98%"));

final DualListField<Stock> lists = new DualListField<Stock>();
lists.setMode(Mode.INSERT);
lists.setFieldLabel("ModelDatas");

ListField<Stock> from = lists.getFromList();
from.setDisplayField("name");
ListStore<Stock> store = new ListStore<Stock>();
store.add(TestData.getShortStocks());
from.setStore(store);
ListField<Stock> to = lists.getToList();
to.setDisplayField("name");
store = new ListStore<Stock>();
to.setStore(store);

panel.add(lists, new FormData("98%"));

TextField<String> email = new TextField<String>();
email.setFieldLabel("Email");
panel.add(email, new FormData("98%"));

panel.addButton(new Button("Cancel"));
panel.addButton(new Button("Save"));

panel.setWidth(550);

store.addStoreListener(new StoreListener<Stock>(){
@Override
public void handleEvent(StoreEvent<Stock> e) {
// TODO Auto-generated method stub
super.handleEvent(e);
Info.display("Name",e.getStore().getModels().get(0).get("name").toString());
}

});




RootPanel.get().add(panel);

sven
12 Dec 2010, 6:20 AM
when i drag and drop this item from toListField to fromListField. I want to access to the Models in the Listener

There will be a IndexOutOfBoundsException. If you drag something away from the tolistfield (the last item), there wont be any item anymore at index 0 and so a IndexOutOfBoundsException is thrown

ishak1981
12 Dec 2010, 6:27 AM
Hello Sven,

Which listener to which object should i add so that i get the models in the store of toListField, when the content of toListField change

sven
12 Dec 2010, 6:31 AM
You listen to all events the "StoreListener" handles. You can do that when you need it. That is not the problem

Try to debug your code.
e.getStore().getModels().get(0) throws an IndexOutOfBoundsException if 0 is an invalid index. Just add a check there.

ishak1981
12 Dec 2010, 6:34 AM
Thank you sven. It was very stupid from me. It works now.