PDA

View Full Version : [FNR] Binding new model fails for checkboxes when panel is not attached



Jose Jeria
19 May 2011, 5:16 AM
System setup used:


Windows 7
GWT 2.3.0
GXT 2.2.4
Firefox 3.6.17


I have an application where a model is bound to several forms and I noticed that binding checkboxes fails for some reason. I am not sure if this is a bug in GXT or if I misunderstood something. Anyway, here we go:

Entry point:


public class DemoEntryPoint implements EntryPoint {

private FormBinding binding1;
private FormBinding binding2;

private ContentPanel panel;
private FormPanel form1;
private FormPanel form2;
private FormPanel activeForm;

private CheckBox one;
private CheckBox two;

@Override
public void onModuleLoad() {
createPanels();
createBinding();
bindModel(new DummyModel(true, false, "Street 1", "first name 1", "second name 1", "Stockholm 1"));

Viewport viewport = new Viewport();
viewport.add(panel);

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

private void createPanels() {
form1 = createForm1();
form2 = createForm2();

panel = createContentPanel();
panel.add(form1);
}

private void createBinding() {
binding1 = new FormBinding(form1, true);
binding1.addFieldBinding(new FieldBinding(one, one.getName()));
binding1.addFieldBinding(new FieldBinding(two, two.getName()));
binding2 = new FormBinding(form2, true);
}

private void bindModel(DummyModel testModel) {
Class<?> className = testModel.getClass();
BeanModelFactory factory = BeanModelLookup.get().getFactory(className);

BeanModel beanModel = factory.createModel(testModel);

binding1.bind(beanModel);
binding2.bind(beanModel);
}

private ContentPanel createContentPanel() {
Button button1 = new Button("First panel");
button1.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
attachForm(form1);
}
});

Button button2 = new Button("Second panel");
button2.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
attachForm(form2);
}
});

ContentPanel panel = new ContentPanel();
panel.setHeaderVisible(false);
panel.addButton(button1);
panel.addButton(button2);
panel.addButton(new Button("Bind new model", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent event) {
if (activeForm.isValid()) {
bindModel(new DummyModel(true, false, "Street 2", "first name 2", "second name 2", "Stockholm 2"));
}
}
}));

return panel;
}

private FormPanel createForm1() {
TextField<String> firstName = new TextField<String>();
firstName.setName("firstName");
firstName.setFieldLabel("First Name");

one = new CheckBox();
one.setBoxLabel("One");
one.setName("one");

two = new CheckBox();
two.setBoxLabel("Two");
two.setName("two");

CheckBoxGroup group = new CheckBoxGroup();
group.setFieldLabel("Numbers");
group.add(one);
group.add(two);

FormPanel form = new FormPanel();
form.setHeading("First panel");
form.add(firstName);
form.add(group);

return form;
}

private FormPanel createForm2() {
TextField<String> name = new TextField<String>();
name.setName("street");
name.setFieldLabel("Street");

FormPanel form = new FormPanel();
form.setHeading("Second panel");
form.add(name);

return form;
}

private void attachForm(FormPanel form) {
if (!form.isAttached()) {
panel.removeAll();
panel.add(form);
panel.layout();

activeForm = form;
}
}
}
DummyModel.class


@SuppressWarnings("serial")
public class DummyModel implements Serializable {
private boolean one;
private boolean two;
private String street;
private String firstName;
private String lastName;
private String city;

public DummyModel() {
}

public DummyModel(boolean one, boolean two, String street, String firstName, String lastName, String city) {
this.one = one;
this.two = two;
this.street = street;
this.firstName = firstName;
this.lastName = lastName;
this.city = city;
}

public boolean isOne() {
return one;
}

public void setOne(boolean one) {
this.one = one;
}

public boolean isTwo() {
return two;
}

public void setTwo(boolean two) {
this.two = two;
}

public String getStreet() {
return street;
}

public void setStreet(String street) {
this.street = street;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}
}
DummyModelBeanMarker.class


@BEAN(DummyModel.class)
public interface DummyModelBeanMarker extends BeanModelMarker {

}
Steps to reproduce:
1. Click on "Second Panel" button
2. Click on "Bind new model" button
3. Go back to first panel by clicing "First Panel" button

Notice that the new model had been bound, but not the checkboxes. Am I missing something here?

sven
19 May 2011, 5:33 AM
Fixed in SVN as of revision 2389

Jose Jeria
19 May 2011, 8:05 AM
Verified fixed.

Thank you very much for the quick fix!

sven
19 May 2011, 8:30 AM
Verified fixed.

Thank you very much for the quick fix!

If all reports would be that detailed or would even take time to write down the steps how to reproduce it, it could most times be that fast ;)