user1469130
user1469130

Reputation: 49

Vaadin form binding exception

When binding a bean containing integer properties to a form, when the form is shown the value of the field is 0 which is normal because that's the integer default value. But when I delete the 0 of the field and put the focus on the next form field (setImmediate = true), I get a nasty exception:

com.vaadin.data.Property$ConversionException: java.lang.reflect.InvocationTargetException
    at com.vaadin.data.util.MethodProperty.convertValue(MethodProperty.java:695)
    at com.vaadin.data.util.MethodProperty.setValue(MethodProperty.java:664)
    at com.vaadin.ui.AbstractField.setValue(AbstractField.java:495)
    at com.vaadin.ui.AbstractTextField.changeVariables(AbstractTextField.java:242)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1460)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1404)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1329)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:761)
    at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:318)
    at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.vaadin.data.util.MethodProperty.convertValue(MethodProperty.java:692)
    ... 22 more
Caused by: java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Unknown Source)
    at java.lang.Integer.parseInt(Unknown Source)
    at java.lang.Integer.<init>(Unknown Source)
    ... 27 more

Of course I can avoid this by setting the field as Required but that's not what I want. I am quite new to Vaadin so do I miss something?

Thank you

Upvotes: 0

Views: 1314

Answers (1)

eugen-fried
eugen-fried

Reputation: 2173

Maybe using Integer wrapper and textField.setNullRepresentation(""); will help

Upvotes: 0

Related Questions