PDA

View Full Version : ComboBox.getValue return null after binding???



lichnost
20 Jan 2009, 5:19 AM
When I call ComboBox.getValue() just after binding, it return null however ComboBox.value field not null. If I select then something selected value returns as well.

Here is the example


public void onModuleLoad() {

TestBean bean = new TestBean();
bean.setName("Main bean");

TestBean nestedBean = new TestBean();
nestedBean.setName("Nested bean");
bean.setNested(nestedBean);


FormPanel form = new FormPanel();
final TextField<String> nameField = new TextField<String>();
nameField.setFieldLabel("Name");
form.add(nameField);

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

TestBean comboBean = new TestBean();
comboBean.setName("Nested bean 2");
store.add(BeanModelLookup.get().getFactory(TestBean.class).createModel(comboBean));

comboBean = new TestBean();
comboBean.setName("Nested bean 3");
store.add(BeanModelLookup.get().getFactory(TestBean.class).createModel(comboBean));

combo.setStore(store);
combo.setFieldLabel("Nested");
combo.setDisplayField("name");
form.add(combo);

final Bindings bindings = new Bindings();
bindings.addFieldBinding(new FieldBinding(nameField,"name"));
bindings.addFieldBinding(new FieldBinding(combo,"nested"));
bindings.bind(BeanModelLookup.get().getFactory(TestBean.class).createModel(bean));
RootPanel.get().add(form);

Button initBtn = new Button("Init", new SelectionListener<ComponentEvent>(){

@Override
public void componentSelected(ComponentEvent ce) {
TestBean bean = new TestBean();
bean.setName("Main bean");

TestBean nestedBean = new TestBean();
nestedBean.setName("Nested bean");
bean.setNested(nestedBean);

bindings.bind(BeanModelLookup.get().getFactory(TestBean.class).createModel(bean));
}

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

Button changeBtn = new Button("Check combobox", new SelectionListener<ComponentEvent>(){

@Override
public void componentSelected(ComponentEvent ce) {
if(combo.getValue()==null)
combo.markInvalid(null);
else Info.display("Yeah!!", "All right");
if(nameField.getValue()==null)
nameField.markInvalid(null);
}

});
RootPanel.get().add(changeBtn);
}Any suggestions?

sven
20 Jan 2009, 5:24 AM
Post some complete example, also with your TestBean class.

lichnost
20 Jan 2009, 5:43 AM
Here is it


public class TestBean implements BeanModelTag, Serializable{

/**
*
*/
private static final long serialVersionUID = 1L;

private TestBean nested;

private String name;

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

public String getName() {
return name;
}

public void setNested(TestBean nested) {
this.nested = nested;
}

public TestBean getNested() {
return nested;
}

}

kolli
20 Jan 2009, 5:59 AM
Are you selecting an item from the combo Box before clicking the changeBtn?? As it returns null if a value is not selected before.

sven
20 Jan 2009, 6:13 AM
I looked into this and maybe found the reason and we will fix it.

lichnost
20 Jan 2009, 6:23 AM
Are you selecting an item from the combo Box before clicking the changeBtn?? As it returns null if a value is not selected before.

Well.. if I'm not selecting an item, then it must return value binded with Bindings, right?

kolli
20 Jan 2009, 6:52 AM
ooh i am really sorry i have no idea about bindings i will take a look into that..
thanks

lichnost
3 Mar 2009, 7:09 AM
any progress for this issue??

brginfo05
4 Jun 2009, 4:29 PM
There is a hack you can do to by pass that problem. I´ll post my code as soon as i can.

brginfo05
5 Jun 2009, 4:41 AM
Forget my hack, its too unstable. Some times work sometimes dont.

lichnost
5 Jun 2009, 6:54 AM
The workaround is to add model to the store manually after binding.

tothit
7 Jun 2009, 4:07 AM
subscribe

brginfo05
7 Jun 2009, 8:45 AM
Now i have another problem. When i select a new combobox value my grid store doesnt update. The textfields again work fine.

brginfo05
7 Jun 2009, 11:05 AM
After some tests a realize that in the method updateModel() any code i put after r.set(property, val) doesnt work. The val is a ModelData type.