Form handling

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:

  1. Only fill in a first name and click on Save: an error will be shown that no last name was entered.
  2. 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!!

Good morning, Peter!

This sounds like it might be a bug in the serialization of objects when using Google App Engine, i.e. the field’s value (or something regarding the value) is not serialized properly.

Could you check the logs and see if there are any serialization errors reported?

Perhaps someone from the R&D team (Artur?) also could comment, since I don’t have much practical experience with GAE.

HTH,
/Jonatan

Jonatan,

Thanks for your very quick response!

I checked GAE’s logs and they don’t show anything, even not on INFO level. My POJO implements Serializable and the concerning fields are just Strings.

Peter

I already solved it. I forgot using GAEApplicationServlet as a servlet class. It works now!

Thanks for your time anyway!