Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
FormBinder handling invalid values
Hello,
I use the FormBinder with a few TextFields containing an IntegerValidator. Usually it works fine: invalid values are shown correctly by the error indicator but every once in a while it crashes by throwing exceptions, when I enter an invalid value and focus out the field. I can't figure out where to catch following exception or why it happens just occasionally.
com.vaadin.data.Buffered$SourceException
at com.vaadin.ui.AbstractField.setValue(AbstractField.java:533)
at com.vaadin.ui.AbstractTextField.changeVariables(AbstractTextField.java:242)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1445)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1393)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1312)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:763)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
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:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:680)
Caused by: com.vaadin.data.Property$ConversionException: java.lang.reflect.InvocationTargetException
at com.vaadin.data.util.MethodProperty.convertValue(MethodProperty.java:697)
at com.vaadin.data.util.MethodProperty.setValue(MethodProperty.java:666)
at com.vaadin.ui.AbstractField.setValue(AbstractField.java:525)
... 20 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.vaadin.data.util.MethodProperty.convertValue(MethodProperty.java:694)
... 22 more
Caused by: java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:470)
at java.lang.Integer.<init>(Integer.java:660)
... 27 more
Any ideas?
Hi,
I guess this is related to just TextField and IntegerValidator, not FormBinder. There is a gotcha that Vaadin does not run validators for empty fields. Based on your stack trace I'd assume the field is trying to commit empty string to your datasource which only accepts integers. So you probably also need to call setRequired(true) for your field (and most probably also setNullRepresentation("") ).
cheers,
matti
Hi Matti,
thank you for the quick response! I removed the IntegerValidator and set the nullRepresentation to "". Now the exception is thrown every time I try to enter " " for example. My bean class contains Integer values so it kind of should cause an error but I would like to intercept it. The fields are not required by the way... they should only cause errors if non integer values are filled in. What can I do?
Keep the IntegerValidator there, so it should catch values that cannot be converted to Integer and which are not empty. Using empty string ("") as null representation and isRequired as false should allow setting null to the value as well (by clearing the field).
cheers,
matti
Then I'm back at square one ;) I have narrowed down the problem though: first time entering a non integer value the error icon is shown - so far so good. Going back to the field and changing it to a another faulty value works too. Entering a valid value after a faulty one is also working. Just when I leave it blank after a validation error occured the exception is thrown. Do you understand this behaviour?