PDA

View Full Version : [CLOSED] Simple ComboBox problem



lucasas
29 Jul 2008, 4:02 AM
SimpleComboBox doesn't work when I set the displayfield attribute. It doesn't display value.

Simple code:


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class Index extends LayoutContainer implements EntryPoint {

public void onModuleLoad() {
List<User> users = new ArrayList<User>();
User user = new User();
user.setName("Lucas");
users.add(user);

SimpleComboBox<User> combo = new SimpleComboBox<User>();
combo.add(users);
combo.setDisplayField("name");
RootPanel.get().add(combo);

}

class User implements Serializable {
private static final long serialVersionUID = 3307344504260878694L;
private String name;

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

public String getName() {
return name;
}
}
}

gslender
29 Jul 2008, 4:13 AM
add a
public String toString() method to User at it will....

lucasas
29 Jul 2008, 5:17 AM
But I want set the displayfield attribute

lucasas
29 Jul 2008, 9:15 AM
Even doing this doesn't work.
I subscribed the toString method and doesn't work.

gslender
29 Jul 2008, 12:57 PM
I'm doing the very same thing and it does work for me... the toString returns the name I want displayed. I also have it working with an Enum - which is cool becuase I have a constant item to refer to item selected etc and it displays correctly with the i18n name... very nice indeed.

Post some sample code that shows it not working....
Cheers,
Grant

darrellmeyer
30 Jul 2008, 8:29 AM
SimpleComboBox does not use the display property. It simply uses the value added to the combo box. If you want to use a ModelData instance with a display property you should not use SimpleComboBox.