How to use/implement non-string fields in Form?

Hi,
I have an Integer field in an object that is used as a BeanItem datasource. FieldFactory creates a textfield out of it. The field works fine when the input is an Integer, and a validator implementation captures character cases. The problem occurs when the user deletes all characters from the textfield and tries to commit (the integer textfield is not mandatory). The following exceptions gets thrown:

com.vaadin.data.Buffered$SourceException
[java]
at com.vaadin.ui.Form.commit(Form.java:342)

com.vaadin.data.Property$ConversionException: java.lang.reflect.InvocationTargetException
at com.vaadin.data.util.MethodProperty.setValue(MethodProperty.java:703)
at com.vaadin.ui.AbstractField.commit(AbstractField.java:226)
at com.vaadin.ui.Form.commit(Form.java:316)

How should I implement forms that have TextFields with other data types than Strings?

Hi,

Sounds like the problem is that the form is trying to assign “null” to a field that is defined to be an int rather than an Integer. It should work if you change your class to store optional data so that they are allowed to be null.

After this you have to check whether the value is null before you use it, of course.

HTH,
/Jonatan