PDA

View Full Version : [CLOSED] Bug in LoadListener



ashleywong
10 Jun 2008, 8:28 PM
I am going to implements a data list which received data from a RPC call. On the loaderLoad method, I wish to pre-select some fields.

However, I found that the loaderLoad() method is not really fired after the loader had loaded the data.


public class DataListStorePage extends LayoutContainer implements EntryPoint {

public void onModuleLoad() {
RootPanel.get().add(this);
}

@Override
protected void onRender(Element parent, int pos) {
super.onRender(parent, pos);

setLayout(new FlowLayout(10));

final DataList list = new DataList();
list.setSelectionMode(SelectionMode.MULTI);
list.setFlatStyle(true);

RpcProxy proxy = new RpcProxy() {

@Override
protected void load(Object loadConfig, AsyncCallback callback) {
callback.onSuccess(TestData.getStocks());
}

};
final BaseListLoader loader = new BaseListLoader(proxy);
loader.addLoadListener(new LoadListener() {

@Override
public void loaderLoad(LoadEvent le) {
Window.alert(list.getItemCount() + "");
}

});

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

DataListBinder<Stock> binder = new DataListBinder<Stock>(list, store);
binder.setDisplayProperty("name");
binder.init();

ContentPanel panel = new ContentPanel();
panel.setFrame(true);
panel.setCollapsible(true);
panel.setAnimCollapse(false);
panel.setButtonAlign(HorizontalAlignment.CENTER);
panel.setIconStyle("icon-list");
panel.setHeading("Store DataList");
panel.setLayout(new FitLayout());
panel.add(list);
panel.setSize(230, 250);

ToolBar toolBar = new ToolBar();

final StoreFilter<Stock> filter = new StoreFilter<Stock>() {
public boolean select(Store store, Stock parent, Stock item,
String property) {
if (item.getName().charAt(0) == 'A') {
return false;
}
return true;
}
};
store.addFilter(filter);

TextToolItem sort = new TextToolItem("Sort");
sort.setIconStyle("my-icon-asc");
sort.addSelectionListener(new SelectionListener() {
public void componentSelected(ComponentEvent ce) {
store.sort("name", SortDir.ASC);
}
});

final ToggleToolItem filterItem = new ToggleToolItem("Filter A's");
filterItem.setIconStyle("icon-filter");
filterItem.addSelectionListener(new SelectionListener() {
public void componentSelected(ComponentEvent ce) {
if (filterItem.isPressed()) {
store.applyFilters("name");
} else {
store.clearFilters();
}

}
});
toolBar.add(sort);
toolBar.add(new SeparatorToolItem());
toolBar.add(filterItem);
panel.setTopComponent(toolBar);

add(panel);

DeferredCommand.addCommand(new Command() {

public void execute() {
loader.load();
}

});
}
}

darrellmeyer
11 Jun 2008, 7:49 PM
It is fired after the load event, but before the list has responded to the event. You should be checking the data in the event:


loader.addLoadListener(new LoadListener() {
@Override
public void loaderLoad(LoadEvent le) {
Window.alert("count: " + ((List)le.data).size());
}
});

If you add your listener after you create the store, your code will work as the stores listener will be executed before yours.

ashleywong
11 Jun 2008, 8:04 PM
Thanks for advance.

Actually, I want to pick up some entries to pre-select. However, le.getData() can only get the List<Stock>. How do I get the DataListItem?

Attached is the available select method of DataList.

ashleywong
11 Jun 2008, 8:08 PM
If you add your listener after you create the store, your code will work as the stores listener will be executed before yours.

Sorry, I got it. Thanks