PDA

View Full Version : DualListField and "nested values"



fother
21 Jul 2009, 4:26 AM
code example


private class Contact extends BaseModel {

private String phone;

public Contact(String phone) {
this.phone = phone;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}
}

private class User extends BaseModel {

private String name;
private Contact contact;

public User(String name, Contact contact) {
this.name = name;
this.contact = contact;
}

public Contact getContact() {
return contact;
}

public String getName() {
return name;
}

public void setContact(Contact contact) {
this.contact = contact;
}

public void setName(String name) {
this.name = name;
}
}

public void onModuleLoad() {

FormPanel panel = new FormPanel();
panel.setHeading("Example");

final DualListField<User> lists = new DualListField<User>();
lists.setFieldLabel("Phone");

ListStore<User> store = new ListStore<User>();
store.setStoreSorter(new StoreSorter<User>());
store.add(new User("diego", new Contact("45-878-098")));

ListField<User> from = lists.getFromList();
from.setDisplayField("contact.phone");
from.setStore(store);

store = new ListStore<User>();
store.setStoreSorter(new StoreSorter<User>());
ListField<User> to = lists.getToList();
to.setDisplayField("contact.phone");
to.setStore(store);

panel.add(lists);
panel.setWidth(550);

RootPanel.get().add(panel);
}


stack trace



com.google.gwt.core.client.JavaScriptException: (TypeError): 'contact' não está definido
number: -2146823279
description: 'contact' não está definido
at com.extjs.gxt.ui.client.core.XTemplate$.overwrite$(Native Method)
at com.extjs.gxt.ui.client.widget.ListView.refresh(ListView.java:386)
at com.extjs.gxt.ui.client.widget.ListView.onRender(ListView.java:696)
at com.extjs.gxt.ui.client.widget.Component.render(Component.java:906)
at com.extjs.gxt.ui.client.widget.Component.render(Component.java:869)
at com.extjs.gxt.ui.client.widget.form.ListField.onRender(ListField.java:318)
at com.extjs.gxt.ui.client.widget.Component.render(Component.java:906)
at com.extjs.gxt.ui.client.widget.Component.render(Component.java:869)
at com.extjs.gxt.ui.client.widget.layout.TableRowLayout.renderComponent(TableRowLayout.java:127)
at com.extjs.gxt.ui.client.widget.Layout.renderAll(Layout.java:249)
at com.extjs.gxt.ui.client.widget.layout.TableRowLayout.onLayout(TableRowLayout.java:121)
at com.extjs.gxt.ui.client.widget.Layout.layout(Layout.java:96)
at com.extjs.gxt.ui.client.widget.Container.doLayout(Container.java:348)
at com.extjs.gxt.ui.client.widget.Container.layout(Container.java:444)
at com.extjs.gxt.ui.client.widget.LayoutContainer.layout(LayoutContainer.java:241)
at com.extjs.gxt.ui.client.widget.Container.layout(Container.java:427)
at com.extjs.gxt.ui.client.widget.LayoutContainer.layout(LayoutContainer.java:236)
at com.extjs.gxt.ui.client.widget.HorizontalPanel.onRender(HorizontalPanel.java:163)
at com.extjs.gxt.ui.client.widget.Component.render(Component.java:906)
at com.extjs.gxt.ui.client.widget.form.MultiField.onRender(MultiField.java:292)
at com.extjs.gxt.ui.client.widget.form.DualListField.onRender(DualListField.java:420)
at com.extjs.gxt.ui.client.widget.Component.render(Component.java:906)
at com.extjs.gxt.ui.client.widget.Component.render(Component.java:869)
at com.extjs.gxt.ui.client.widget.layout.FormLayout.renderField(FormLayout.java:275)
at com.extjs.gxt.ui.client.widget.layout.FormLayout.renderComponent(FormLayout.java:239)
at com.extjs.gxt.ui.client.widget.Layout.renderAll(Layout.java:249)
at com.extjs.gxt.ui.client.widget.Layout.onLayout(Layout.java:230)
at com.extjs.gxt.ui.client.widget.layout.AnchorLayout.onLayout(AnchorLayout.java:77)
at com.extjs.gxt.ui.client.widget.Layout.layout(Layout.java:96)
at com.extjs.gxt.ui.client.widget.Layout$2.handleEvent(Layout.java:59)
at com.extjs.gxt.ui.client.util.DelayedTask$1.run(DelayedTask.java:30)
at com.extjs.gxt.ui.client.util.DelayedTask.delay(DelayedTask.java:52)
at com.extjs.gxt.ui.client.widget.Layout.onResize(Layout.java:240)
at com.extjs.gxt.ui.client.widget.Layout$1.handleEvent(Layout.java:52)
at com.extjs.gxt.ui.client.widget.Layout$1.handleEvent(Layout.java:1)
at com.extjs.gxt.ui.client.event.BaseObservable.callListener(BaseObservable.java:176)
at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:96)
at com.extjs.gxt.ui.client.widget.Component.fireEvent(Component.java:444)
at com.extjs.gxt.ui.client.widget.BoxComponent.setSize(BoxComponent.java:572)
at com.extjs.gxt.ui.client.widget.BoxComponent.afterRender(BoxComponent.java:635)
at com.extjs.gxt.ui.client.widget.ScrollContainer.afterRender(ScrollContainer.java:194)
at com.extjs.gxt.ui.client.widget.Component.render(Component.java:961)
at com.extjs.gxt.ui.client.widget.Component.onAttach(Component.java:1466)
at com.extjs.gxt.ui.client.widget.Container.onAttach(Container.java:453)
at com.extjs.gxt.ui.client.widget.form.FormPanel.onAttach(FormPanel.java:452)
at com.google.gwt.user.client.ui.Widget.setParent(Widget.java:393)
at com.google.gwt.user.client.ui.Panel.adopt(Panel.java:119)
at com.google.gwt.user.client.ui.ComplexPanel.add(ComplexPanel.java:86)
at com.google.gwt.user.client.ui.AbsolutePanel.add(AbsolutePanel.java:80)

sven
21 Jul 2009, 4:31 AM
There are several issues in your code. There is no field called "contact" or "phone".

fother
21 Jul 2009, 4:33 AM
the instance of the DualListField its the class "User", the class "User" have the attribute "contact" that its one instance of the class "Contact" that have the attribute "phone"..

so if its wrong.. why if I use in a grid the same situation work fine?

fother
21 Jul 2009, 4:36 AM
other way.. if my code its wrong you can correct? ;)

fother
21 Jul 2009, 4:51 AM
if I use this



ListField<User> from = lists.getFromList();
from.setDisplayField("contact");
from.setStore(store);


dont return error.. but dont appears nothing..

fother
21 Jul 2009, 5:12 AM
like a combobox needs do this gambs..



ListField<User> from = lists.getFromList();
from.setDisplayField("customName");
from.getListView().setModelProcessor(new ModelProcessor<User>() {
@Override
public User prepareData(User model) {
if (model != null) {
model.set("customName", model.getContact().getPhone());
}
return model;
}
});