PDA

View Full Version : How to use Models, Binders, and Readers



fernando
12 Jun 2008, 11:23 AM
Hi Guy's,

I'm trying to get a handle on how to make remote calls and then have that data loaded into an Ext component. For an example I am trying to load some simple data into a combo box.
Here is my code:


ContentPanel panel = new ContentPanel();
panel.setFrame(true);
panel.setCollapsible(true);
panel.setAnimCollapse(false);
panel.setButtonAlign(HorizontalAlignment.CENTER);
panel.setIconStyle("icon-table");
panel.setHeading("XML Table Demo");
panel.setShadow(true);
panel.setSize(675, 450);

//setup the model
ModelType type = new ModelType();
type.recordName = "name";
type.addField("name");
type.addField("id");

//request the data
final RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL);
HttpProxy proxy = new HttpProxy(builder);

// need a loader, proxy, and reader
JsonReader reader = new JsonReader(type);

final BaseListLoader loader = new BaseListLoader(proxy, reader);
loader.load();
final ListStore store = new ListStore(loader);


final ComboBox combo = new ComboBox();
combo.setFieldLabel("id");
combo.setDisplayField("name");
combo.setWidth(210);
combo.setStore(store);
panel.add(combo);

RootPanel.get("slot1").add(panel);


Here is the json that is returned from the server:


[{"name": {"name": "Tim", "id": 1}}, {"name": {"name": "Rachel", "id": 2}}]


A call is made to the server but nothing renders inside the comboBox. I havn't bound the store to the comboBox because I'm not sure how to. Unlike Trees, Tables, and Lists there is no dedicated Binder to use.

Any hints as to how to link together loaders, stores, binders, and components would be very much appreciated.

fernando
12 Jun 2008, 11:44 AM
Sorry didn't see the previous post.

However, I'm still not sure about how to 'Edit BaseModel to your own Model type'