Problem with TextField and Null Representation

Hi all!

I have a TextField, with a setNullRepresentation(“”).

This field, is binded to a Integer field, via BeanItem.

I have a IntegerValidator on this field, that only try to do a Integer.parsetInt on the value, otherwise, it returns the error.

After the validator is invoked, if the user removes all chars of the field (that is allowed to be null), via reflection, the BeanItem try to put the null representation as a empty string, on the Bean Integer field, causing a exception:

	at com.vaadin.event.ListenerMethod.receiveEvent(
	at com.vaadin.event.EventRouter.fireEvent(
	at com.vaadin.ui.AbstractComponent.fireEvent(
	at com.vaadin.ui.Button.fireClick(
	at com.vaadin.ui.Button.changeVariables(
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(
	at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(
	at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(
	at javax.servlet.http.HttpServlet.service(
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(
	at org.apache.catalina.core.StandardWrapperValve.invoke(
	at org.apache.catalina.core.StandardContextValve.invoke(
	at org.apache.catalina.core.StandardHostValve.invoke(
	at org.apache.catalina.valves.ErrorReportValve.invoke(
	at org.apache.catalina.core.StandardEngineValve.invoke(
	at org.apache.catalina.connector.CoyoteAdapter.service(
	at org.apache.coyote.http11.Http11Processor.process(
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
Caused by:$SourceException
	at com.vaadin.ui.Form.commit(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at com.vaadin.event.ListenerMethod.receiveEvent(
	... 26 more
Caused by:$SourceException
	at com.vaadin.ui.AbstractField.commit(
	at com.vaadin.ui.Form.commit(
	... 32 more
Caused by:$ConversionException: java.lang.reflect.InvocationTargetException
	at com.vaadin.ui.AbstractField.commit(
	... 33 more
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
	at java.lang.reflect.Constructor.newInstance(
	... 34 more
Caused by: java.lang.NumberFormatException: For input string: ""
	at java.lang.NumberFormatException.forInputString(
	at java.lang.Integer.parseInt(
	at java.lang.Integer.<init>(
	... 39 more

How can I avoid that?

You could use a simple PropertyFormatter:

public class LenientIntegerFormatter extends PropertyFormatter {
    public LenientIntegerFormatter(Property propertyDataSource) {

    public Object parse(String formattedValue) throws Exception {
        if ("".equals(formattedValue))
            return null;
            return Integer.valueOf(formattedValue);

    public String format(Object value) {
        if (value == null)
            return "";

        return ((Integer) value).toString();

    public Class<?> getType() {
        return String.class;

    Form form =
    Field countField = form.getField("count"); 
            new LenientIntegerFormatter(

There could be some other way as well, I’m not sure.

Maybe it would be usefull for somebody.

I had the similar issue. And I found the solution in example All that I needed was: add line with TextField.setNullSettingAllowed(true) in createField() method.


I have the same problem. I use following field definition.

TextField field = new TextField(caption);
field.addValidator(new IntegerValidator(“This is not an integer!!!”));

I have debugged into class AbstractField.setValue(). Here the value is set, but the given “NullRepresentation” is not used here.

So, from my point of view one can derive from TextField and overwrite the setValue method to invoke the real setValue with
the desired “NullSetValueRepresentation” !!??

so long,

I’m using VAADIN 6.7.9

I forgot to write that I use the TextField in a Form with following behavior …


It seems that my problem is solved with following solution …

I use following Field definition now …

TextField field = new IntegerTextField(caption);
field.addValidator(new IntegerValidator(“This is not an Integer!”));

I use following derived Field class …

public class IntegerTextField extends TextField
private static final long serialVersionUID = 1L;

public IntegerTextField(String caption)

 * Sets the value of the field.
 * @param newValue
 *            the New value of the field.
 * @param repaintIsNotNeeded
 *            True iff caller is sure that repaint is not needed.
 * @throws Property.ReadOnlyException
 * @throws Property.ConversionException
protected void setValue(Object newValue, boolean repaintIsNotNeeded)
        throws Property.ReadOnlyException, Property.ConversionException {
	if( newValue instanceof String)
    	String value = (String) newValue;
    		super.setValue("0", repaintIsNotNeeded);	
	super.setValue(newValue, repaintIsNotNeeded);


The nice effect is now, when I type a blank string into the field, this empty string is changed into “0”.
The TextField implementation now can set this “0” value to my Integer property. And after that no
validation error is raised.

What is missing here in the TextField implementation is a possibility to say …

→ If the value is a special value (empty String ot null) than set a default value

My solution is the following:

TextField field = new TextField();


OR 2.
Overide the form’s commit() method:
public void commit() throws Buffered.SourceException, InvalidValueException {
// handle the “” string, i.e.
String myPropertyField = (String) getField(“myProperty”).getValue();
if (myPropertyField != null && “”.equals(myPropertyField.trim())) {