View Full Version : Combobox in tabpanel
winter
2 Jul 2008, 9:50 AM
Take for example the TabPanel form of the demo. If you would change it so the second tab contains a combobox, it would generate a nullpointerexception if you'd try to set the value of the combobox.. because the component isn't rendered yet. This does work however with TextFields.
darrellmeyer
3 Jul 2008, 10:13 AM
Please include some test code (http://extjs.com/forum/showthread.php?t=40289).
winter
7 Jul 2008, 5:31 AM
public class Test implements EntryPoint {
public void onModuleLoad() {
LayoutContainer container = new LayoutContainer();
FormPanel panel = new FormPanel();
panel.setHeaderVisible(false);
panel.setBodyBorder(false);
panel.setLayout(new FitLayout());
TabPanel tabs = new TabPanel();
//tab one
TabItem tabOne = new TabItem();
tabOne.setText("Tab one");
tabOne.setLayout(new FormLayout());
TextField<String> field = new TextField<String>();
field.setFieldLabel("field label");
field.setValue("field value");
tabOne.add(field);
tabs.add(tabOne);
//tab two
TabItem tabTwo = new TabItem();
tabTwo.setText("Tab two");
tabTwo.setLayout(new FormLayout());
final TextField<String> testField = new TextField<String>();
testField.setFieldLabel("testField");
tabTwo.add(testField);
final ComboBox<TestElement> testCombo = new ComboBox<TestElement>();
testCombo.setFieldLabel("testCombo");
ListStore <TestElement> testStore = new ListStore <TestElement>();
ArrayList <TestElement> testElements = new ArrayList <TestElement>();
testElements.add(new TestElement("Y"));
testElements.add(new TestElement("N"));
testStore.add(testElements);
testCombo.setStore(testStore);
testCombo.setDisplayField("value");
tabTwo.add(testCombo);
tabs.add(tabTwo);
panel.add(tabs);
Button button = new Button("test");
button.addListener(Events.Select,new Listener(){
public void handleEvent(BaseEvent be) {
testField.setValue("Y");
testCombo.setRawValue("Y");
}
});
panel.addButton(button);
panel.setSize(340, 180);
container.add(panel);
RootPanel.get().add(container);
}
public class TestElement extends BaseModel{
private static final long serialVersionUID = 1L;
public TestElement(){
}
public TestElement(String value) {
set("value", value);
}
public String getValue() {
return (String) get("value");
}
public String toString() {
return getValue();
}
}
}
Well the problem is that I have to use setRawValue for setting the combobox's value, which skips the rendering validation. I could use testCombo.setValue(new TestElement("Y")); in this example; but it gets more complex with real life examples with multiple arguments in it's constructor. Guess I was a bit quick to post this under the bug section, probably better to ask for an enhancement. I was thinking of a sortalike method to "select (int index)" : "select (String value)".
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.