PDA

View Full Version : Combobox setDisplayField



fother
19 Feb 2009, 4:47 AM
GXT: 1.2.3
GWT: 1.5.3

you can see that when using nested attribute to show the display field.. the list don't show nothing..

App


public void onModuleLoad() {

final ComboBox<BeanModel> combo = new ComboBox<BeanModel>();

RpcProxy proxy = new RpcProxy() {

@Override
protected void load(Object loadConfig, AsyncCallback callback) {

RPCExample.Util.getInstance().getBeans(callback);
}
};

ListLoader loader = new BaseListLoader(proxy, new BeanModelReader());
ListStore store = new ListStore(loader);

combo.setDisplayField("music.name");
combo.setStore(store);
combo.setMinChars(1);

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


RPCExampleImpl


public List<Customer> getBeans() {
List<Customer> customers = new ArrayList<Customer>();

customers.add(new Customer("diego", "xxxx@foo.com", 1, new Music("diego music")));
customers.add(new Customer("felipe", "xxxx@foo.com", 1, new Music("felipe music")));
customers.add(new Customer("alan", "xxxx@foo.com", 1, new Music("alan music")));
customers.add(new Customer("gordo", "xxxx@foo.com", 1, new Music("gordo music")));

return customers;
}


Music


public class Music implements Serializable {

private String name;

public Music() {

}

public Music(String name) {
this.name = name;
}

public String getName() {
return name;
}
}


Customer


public class Customer implements Serializable {

private String name;
private String email;
private int age;
private Music music;

public Customer() {

}

public Customer(String name, String email, int age, Music music) {
this.age = age;
this.email = email;
this.name = name;
this.music = music;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getName() {
return name;
}

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

public Music getMusic() {
return music;
}

public void setMusic(Music music) {
this.music = music;
}
}

fother
19 Feb 2009, 4:58 AM
search in the forum I find this..

http://www.extjs.com/forum/showthread.php?p=192361#post192361

how I can do that..

Combo uses the Template class, so you will have to "flatten" your data for use in Combo

sdc
19 Feb 2009, 7:56 AM
Instead of :

combo.setDisplayField("music.name");Use :



combo.setPropertyEditor(new ListModelPropertyEditor<BeanModel>(
"customName") {
public String getStringValue(BeanModel value) {
return ((Customer) value.getBean()).getMusic().getName();
}
});
combo.getView().setModelProcessor(new ModelProcessor<BeanModel>() {
@Override
public BeanModel prepareData(BeanModel model) {
if (model != null)
model.set("customName", ((Customer) model.getBean())
.getMusic().getName()
);
return model;
}
});

berbaquero
4 Mar 2010, 9:24 AM
Helloi! This is my first post...

I am having this same problem: the ComboBox doesn't show the values from RPC callback result...

I'm also using BeanModel, RpcProxy, BaseListLoader and ListStore...

In my case, however, I have LegalProvider and a NaturalProvider, which inherits from Provider class.

In my RPC call, I get the toString result from each of the child clasess, all in the same List...

But I can't seem to find a way to show them on the ComboBox :-/

I hope you can find some kind of solution, and I hope I made myself clear enough...

Thanks!