PDA

View Full Version : [FIXED] FormBinding issue with ComboBox



hbrands
2 Mar 2009, 2:44 AM
I have a situation where the selected combobox value is not committed to the
bound property of a source bean.

Attached is an example that demonstrates the issue.
Class MyBean has a property 'value' of type 'MyValue' that is bound to a ComboBox.
If I select a value by mouse from the drop down list of the ComboBox, the value is committed correctly to the bean, as shown by the log message in the bean setter method.

If I begin to type a value into the text field of the ComboBox and autocomplete the
value by using the TAB-key or by using ENTER and then the TAB-key, the value is
not committed to the bean.

Is this a bug or a problem in my code?

(I want the ComboBox to be editable with type-ahead-filter active, but allowed values
are restricted to the ListStore values. The user should be able to select a value this way without the mouse)

Thanks,
Holger

P.S.: I'm using GXT 1.2.3 on Windows XP in hosted modus and web modus with Firefox 3.0.6.



public class ComboBoxBug implements EntryPoint {

private static NumberConstants NUMBER_CONSTANTS;

private final LayoutContainer contentContainerPanel = new LayoutContainer();

private Widget content;

private final Viewport viewport = new Viewport();

public void onModuleLoad() {
ThemeManager.register(Slate.SLATE);
contentContainerPanel.setLayout(new FitLayout());
viewport.setLayout(new BorderLayout());
final BorderLayoutData westLayoutData = new BorderLayoutData(LayoutRegion.WEST, 200);
westLayoutData.setMargins(new Margins(5));
westLayoutData.setSplit(true);
westLayoutData.setCollapsible(true);
final BorderLayoutData centerLayoutData = new BorderLayoutData(LayoutRegion.CENTER);
centerLayoutData.setMargins(new Margins(5, 5, 5, 0));
viewport.add(contentContainerPanel, centerLayoutData);
final BorderLayoutData northLayoutData = new BorderLayoutData(LayoutRegion.NORTH, 33);
northLayoutData.setMargins(new Margins());
RootPanel.get().add(viewport);
NUMBER_CONSTANTS = (NumberConstants) GWT.create(NumberConstants.class);
final Widget initialContent = createInitialContent();
setContent(initialContent);
GWT.log("groupingSeparator=" + NUMBER_CONSTANTS.groupingSeparator(), null);
GWT.log("decimalSeparator=" + NUMBER_CONSTANTS.decimalSeparator(), null);
}

private Widget createInitialContent() {
BeanModelFactory factory = BeanModelLookup.get().getFactory(MyBean.class);
final MyBean data = new MyBean();
data.setComment("Test");
BeanModel beanModel = factory.createModel(data);
final FormPanel result = new FormPanel();
result.setFrame(true);
result.setHeaderVisible(false);
result.setBodyBorder(false);
result.setBorders(false);
result.setLabelWidth(120);
result.setLabelAlign(LabelAlign.TOP);
result.setSize(250, 450);

final ComboBox<BeanModel> valueField = new ComboBox<BeanModel>();
valueField.setMinChars(1);
valueField.setStore(createListStore());
valueField.setDisplayField("name");
valueField.setAllowBlank(false);
valueField.setTypeAhead(true);
valueField.setSelectOnFocus(true);
valueField.setEditable(true);
valueField.setForceSelection(true);
valueField.setTriggerAction(TriggerAction.ALL);
valueField.setName("value");
valueField.setFieldLabel("Value");
result.add(valueField);
final TextField<String> commentField = new TextField<String>();
commentField.setSelectOnFocus(true);
commentField.setAutoValidate(true);
commentField.setName("comment");
commentField.setFieldLabel("Comment");
result.add(commentField);
final FormBinding binding = new FormBinding(result, true);
binding.bind(beanModel);
return result;
}

private void setContent(Widget newContent) {
if (content != null) {
contentContainerPanel.remove(content);
content = null;
}
contentContainerPanel.add(newContent);
content = newContent;
contentContainerPanel.layout();
contentContainerPanel.show();
}

private ListStore<BeanModel> createListStore() {
final List<MyValue> values = new ArrayList<MyValue>();
values.add(new MyValue("A value"));
values.add(new MyValue("B value"));
values.add(new MyValue("C value"));

final BeanModelFactory factory = BeanModelLookup.get().getFactory(MyValue.class);
final List<BeanModel> valueModels = factory.createModel(values);
final ListStore<BeanModel> result = new ListStore<BeanModel>();
result.add(valueModels);
return result;
}

public static class MyBean implements BeanModelTag, Serializable {
private MyValue value;

private String comment;

public MyValue getValue() {
return value;
}

public void setValue(MyValue value) {
GWT.log("MyBean.setValue: " + value, null);
this.value = value;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}
}

public static class MyValue implements BeanModelTag, Serializable {
private String name;

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

public String getName() {
return name;
}

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

@Override
public String toString() {
return name;
}
}

}

sven
2 Mar 2009, 4:30 AM
This is a duplicate report. Please use the search before opening new bug reports.

hbrands
2 Mar 2009, 4:52 AM
You're right.
I found this thread:
http://www.extjs.com/forum/showthread.php?t=60243
But it's marked as fixed and commented as fixed for 1.2.3.
The last comment in that thread indicates,
that it's not fixed in 1.2.3, a confirmation pending...
So, take the time I invested in making this test case as
a friendly reminder for this issue ;-)

Thanks,
Holger

mabco
15 Mar 2009, 9:22 AM
I would also like to know when this is going to be fixed. Could we get an answer? It's definitely not fixed in 1.2.3; I just tested it. (Thanks, Holger, for the example code.).

sven
15 Mar 2009, 2:11 PM
With 1.2.4.

sven
1 Apr 2009, 4:17 AM
Fixed in SVN.