So here is my code, commented. Maybe someone spots my mistake, any
comments are welcome:
This is a simple app just to demo my problem.
The entry points creates the UI, the bean to be edited and populates
the properties with empty strings. The bean is then "displayed/
rendered/ edited" until save is pressed.
I do not change any field: I just run the gwt-app and click on save.
Hoping to get shit-in-shit-out, but I get null values out. If I
populate with anything other than empty strings it works perfectly.
Tested with gwt 2.3 and gwt built from trunk.
What am I missing?
public class SimpleEditorSample implements EntryPoint {
@Override
public void onModuleLoad() {
PersonEditor personEditor = new PersonEditor();
Person toBeEdited = new Person();
// populate with empty strings...
toBeEdited.setFullname("");
toBeEdited.setBeruf("");
personEditor.edit(toBeEdited);
RootLayoutPanel.get().add(personEditor);
}
}
The editor as its UI defined using uibinder, so here is the xml,
nothing special here:
<g:HTMLPanel>
<p>
<g:Label>Name</g:Label>
<g:TextBox ui:field="fullname" />
</p>
<p>
<g:Label>Beruf</g:Label>
<g:TextBox ui:field="beruf" />
</p>
<p>
<g:Button ui:field="save">Save</g:Button>
<g:Button ui:field="cancel">Cancel</g:Button>
</p>
</g:HTMLPanel>
</ui:UiBinder>
All the magic happens in the PersonEditor class. UIBinding and Editor
gwt-deferred binding magic first, injected uifields, initialization in
the standard constructor, edit and save methods:
public class PersonEditor extends Composite implements Editor<Person>
{
private static PersonEditorUiBinder uiBinder =
GWT.create(PersonEditorUiBinder.class);
interface PersonEditorUiBinder extends UiBinder<Widget,
PersonEditor> {
}
interface Driver extends SimpleBeanEditorDriver<Person,
PersonEditor> {
}
Driver driver = GWT.create(Driver.class);
@UiField
TextBox fullname;
@UiField
TextBox beruf;
@UiField
Button save;
public PersonEditor() {
initWidget(uiBinder.createAndBindUi(this));
driver.initialize(this);
}
public void edit(Person p) {
driver.edit(p);
log(p);
}
private void log(Person p2log) {
GWT.log("Fullname: " + p2log.getFullname());
GWT.log("Beruf: " + p2log.getBeruf());
}
@UiHandler("save")
void onSaveClick(ClickEvent e) {
GWT.log("Beruf UI field value: " + beruf.getValue());
GWT.log("going to flush...");
Person flushedPerson = driver.flush();
GWT.log("flushed...");
GWT.log("Beruf UI field value: " + beruf.getValue());
log(flushedPerson);
}
@UiHandler("cancel")
void onCancelClick(ClickEvent e) {
GWT.log("edit cancelled, go away...");
}
}
And finally, the bean being edited: a POJO, no constructor, two
properties mapped to two attributes:
public static class Person implements Serializable {
private String fullname;
private String beruf;
public String getFullname() {
return fullname;
}
public void setFullname(String name) {
this.fullname = name;
}
public String getBeruf() {
return beruf;
}
public void setBeruf(String beruf) {
this.beruf = beruf;
}
}