CustomField Add-On Problems on Validator and Commit

Good evening,
I discovered a few days ago this little add-on. I find it very useful and well done, however I have some problems using the embedded form. Mainly I am not able to use a validator (precisely an EmailValidator) inside the embedded form and also I can’t set the read only mode after the commit action.

To be specific, I have a form which contains another embedded form (with 2 TextFields, email and password). Inside the class which extends CustomField I created a FieldFactory and I added an EmailValidator to the TextField. This is the code:


@Override
public Field createField(Item item, Object propertyId, Component uiContext) {
   Field field = super.createField(item, propertyId, uiContext);

   if (propertyId.equals("email")) {
      userField = new TextField("Email");
      userField.setNullRepresentation("");
      userField.addValidator(new EmailValidator("The Email address is invalid'"));
      return userField;
   }
}

However when I commit the form above I am able to see that the BeanItem is not updated, but the form does not show any message.

Regarding the second question, I put the setReadOnly(true) in the overrided commit() method inside the class which extends CustomField, but after clicking on the button the embedded form remains in edit mode. Am I doing something wrong?

Any kind of help will be appreciated.

Thank you

The EmbeddedForm in the demo package of the CustomField add-on has known (and unknown) limitations and bugs, especially concerning the removal of fields when changing data sources but probably also for other situations. I would not be surprised of the two issues you mentioned, at least I never tested the Form-level read-only mode for embedded forms.

If you can upgrade to Vaadin 6.6 (available next week), I would recommend trying the new nested property support, e.g. teamBeanContainer.addNestedContainerProperty(“manager.address.street”) - see also
this thread
. This would be the cleanest solution if applicable in your case.

As a second option, you could use a “proxy item” and a single form, e.g. based on a PropertySetItem with references to the properties of the different items.

Alternatively, patches to EmbeddedForm would be welcome - but do note that the short class is deceptively complicated to get to work right.

Thank you for your help! If you can assure me that, with the new nested property support in Vaadin 6.6, I will be able to manage beans embedded in other beans, I will use it for sure. I think this is the smartest solution. Interesting thread by the way.

Maurizio