Hi,
I tried implementing a simple form bound to a POJO. You can take a look at it on
http://apps.limburgie.be
. It is running on Vaadin 6.1.1 + Google App Engine. You can see the code for my Form class below.
If you perform the following tasks, things go wrong:
- Only fill in a first name and click on Save: an error will be shown that no last name was entered.
- Now enter the last name. The form complains that no first name is entered, which is clearly not the case. It seems like the first name’s value was not saved between those two validations.
Is this normal behaviour and, if yes, how can I make this work like the form in the Vaadin components demo? The source looks quite identical to me… This is my code:
public class PersonForm extends Form {
private Person person;
public PersonForm() {
person = new Person();
setCaption("Create new user");
setDescription("Enter this form to create a new user.");
setFormFieldFactory(new FormFieldFactory() {
@Override
public Field createField(Item item, Object propertyId, Component uiContext) {
String pid = (String) propertyId;
if(pid.equals("firstName")) {
TextField field = new TextField("First name");
field.setRequired(true);
field.setRequiredError("First name cannot be empty");
return field;
} else if(pid.equals("lastName")) {
TextField field = new TextField("Last name");
field.setRequired(true);
field.setRequiredError("Last name cannot be empty");
return field;
} else if(pid.equals("birthDate")) {
DateField dateField = new DateField("Birth date");
dateField.setDateFormat("dd/MM/yyyy");
return dateField;
}
return null;
}
});
setItemDataSource(new BeanItem(person));
setVisibleItemProperties(new String[] {"firstName", "lastName", "birthDate", "hobbies"});
setWriteThrough(false);
setInvalidCommitted(false);
HorizontalLayout okbar = new HorizontalLayout();
okbar.setSpacing(true);
okbar.setHeight("25px");
getFooter().addComponent(okbar);
Button saveButton = new Button("Save", new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
try {
commit();
} catch(Exception e) {
// let form handle errors
}
}
});
okbar.addComponent(saveButton);
okbar.setComponentAlignment(saveButton, Alignment.TOP_RIGHT);
}
}
Thanks in advance!!