ListBox and Data Binding

339 views
Skip to first unread message

Tyo

unread,
May 26, 2011, 9:11:51 AM5/26/11
to Google Web Toolkit
I'm novice in GWT, help pls with my problem.
I try to bind complex data to UI via GWT Editor mechanism. It works
perfectly when binding String fields to TextBox widgets, but I cannot
understand how to bind any field to ListBox widget.
Look at following example, pls


Bean class:

public class MyData implements Serializable {
String name;
int gender;
...getters and setters here...

Editor:

public class MyEditor extends Composite implements Editor<MyData> {
interface Binder extends UiBinder<Widget,MyEditor> {}
private static Binder binder = GWT.create(Binder.class);
@UiField TextBox name;
@UiField ListBox gender;
public MyEditor() { initWidget(binder.createAndBindUi(this)); }
}

Editor's *.ui.xml:

Name:<g:TextBox ui:field="name"/></dev>
<g:ListBox ui:field="gender">
<g:item value="0">Male</g:item>
<g:item value="1">Female</g:item>
<g:item value="2">Shemale</g:item>
</g:ListBox>

And that's invoking class:

public class MyForm extends Composite {
interface Driver extends SimpleBeanEditorDriver<MyData,MyEditor> {}
private Driver driver = GWT.create(Driver.class);
MyEditor editor;
ClickHandler handler = new ClickHandler() {
public void onClick(ClickEvent event) {
MyData myData = driver.flush();
Window.alert("Name=" + myData.getName() + "; Gender=" +
myData.getGender());
}
};

public void drawMe(FlowPanel panel) {
panel.clear();
editor = new MyEditor();
driver.initialize(editor);
MyData myData = new MyData();
driver.edit(myData);
panel.add(editor);
Button button = new Button("Press Me");
button.addClickHandler(handler);
panel.add(button);
}
}

After entering data and pressing button <Press Me> I see correct value
of String variable "name" in Alert box, but int variable "gender"
always =0, independently of current state of ListBox.

What may be wrong with my code?.

Craig Mitchell

unread,
Sep 19, 2011, 12:15:59 AM9/19/11
to google-we...@googlegroups.com
Use ValueListBox, not ListBox.
Reply all
Reply to author
Forward
0 new messages