com.vaadin.data.Buffered$SourceException from Form.commit()

Hi Everybody,

I have a basic problem with Form. Tried to solve this, but could not figure it out. I need your help. Here is my problem:-

I have a Form with a data source attached to it. I am trying to update the data in the form. On click of update button, I am first calling Form.commit() and then updating the bean in database. It works fine, except in one case. There is a field of Integer type in bean class. If I don’t give any value to this field then throwing following error.

14:41:05,346 ERROR [de.mte.dialog.RefDataDialog]
(http–0.0.0.0-8080-6) Failed to modify instance (null): com.vaadin.data.Buffered$SourceException
at com.vaadin.ui.Form.commit(Form.java:365) [vaadin-6.8.2.jar:6.8.2]

at de.mte.dialog.RefDataDialog.doOkAction(RefDataDialog.java:311) [classes:]

at de.mte.dialog.RefDataDialog.buttonClick(RefDataDialog.java:255) [classes:]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_31]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_31]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_31]

at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_31]

at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510) [vaadin-6.8.2.jar:6.8.2]

at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164) [vaadin-6.8.2.jar:6.8.2]

at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1219) [vaadin-6.8.2.jar:6.8.2]

at com.vaadin.ui.Button.fireClick(Button.java:567) [vaadin-6.8.2.jar:6.8.2]

at com.vaadin.ui.Button.changeVariables(Button.java:223) [vaadin-6.8.2.jar:6.8.2]

at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1460) [vaadin-6.8.2.jar:6.8.2]

at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1404) [vaadin-6.8.2.jar:6.8.2]

at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1329) [vaadin-6.8.2.jar:6.8.2]

at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:761) [vaadin-6.8.2.jar:6.8.2]

at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:318) [vaadin-6.8.2.jar:6.8.2]

at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501) [vaadin-6.8.2.jar:6.8.2]

at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]

at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]

at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]

at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_31]

Caused by: com.vaadin.data.Buffered$SourceException
at com.vaadin.ui.AbstractField.commit(AbstractField.java:273) [vaadin-6.8.2.jar:6.8.2]

at com.vaadin.ui.Form.commit(Form.java:339) [vaadin-6.8.2.jar:6.8.2]

... 32 more

Caused by: com.vaadin.data.Property$ConversionException: java.lang.reflect.InvocationTargetException
at com.vaadin.data.util.MethodProperty.convertValue(MethodProperty.java:695) [vaadin-6.8.2.jar:6.8.2]

at com.vaadin.data.util.MethodProperty.setValue(MethodProperty.java:664) [vaadin-6.8.2.jar:6.8.2]

at com.vaadin.ui.AbstractField.commit(AbstractField.java:268) [vaadin-6.8.2.jar:6.8.2]

... 33 more

Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedConstructorAccessor121.newInstance(Unknown Source) [:1.6.0_31]

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [rt.jar:1.6.0_31]

at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_31]

at com.vaadin.data.util.MethodProperty.convertValue(MethodProperty.java:692) [vaadin-6.8.2.jar:6.8.2]

... 35 more

Caused by: java.lang.NumberFormatException: For input string: “”
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) [rt.jar:1.6.0_31]

at java.lang.Integer.parseInt(Integer.java:470) [rt.jar:1.6.0_31]

at java.lang.Integer.<init>(Integer.java:660) [rt.jar:1.6.0_31]

... 39 more

Why is it taking empty string? Or how should I handle this if I have to use Form.commit() ? I don’t want to check the value
of each field before commit.

Related to this I have one more question. My update method can throw an exception. On exception I have to revert the changes in bean, that happened because of Form.commit() call?

Thanks in advance!

The commit is failing because you are trying to set the value from an empty TextField into a method that accepts Integers:

Caused by: java.lang.NumberFormatException: For input string: ""

The value is often null, but can also be an empty String, which causes the Exception. In Vaadin 7 you can fix this by calling TextField.setConverter(Integer.class), in Vaadin 6 you have to convert the value yourself before committing.

Thank you Thomas for your reply. I am using vaadin 6.7.5.

Do you have any idea on my second question.


“My update method can throw an exception. On exception I have to revert the changes in bean, that happened because of Form.commit() call?”

How can I revert the changes in bean in this case. Is there any method in Form which can do so? One way is to keep a back up before calling Form.commit, which I don’t want to do.

Unfortunately, there is no built-in backup of beans in vaadin; you need to fix failed commits yourself. Good news is that all your changes aren’t discarded; so the user can only fix the thing that failed and try again. But if you want to reset the form to the previously stored state you have to do it yourself, as I mentioned already.

Thank you Thomas. Thank you for the quick reply.