ClassCastException when Commit Form - Solved

Hi all.
Im starting with Vaadin, and im trying to Work with the Form Component.

Im using a BeanItem as container, but when I try to commit the form, I Have a ClassCastException, because the form try to use a method of my persistence POJO (void setId(Integer id)), as String.

Here the stack trace:


com.vaadin.event.ListenerMethod$MethodException
Cause: com.vaadin.data.Buffered$SourceException
	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:507)
	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
	at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1154)
	at com.vaadin.ui.Button.fireClick(Button.java:371)
	at com.vaadin.ui.Button.changeVariables(Button.java:193)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1094)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:590)
	at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:266)
	at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:476)
	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:857)
	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:662)
Caused by: com.vaadin.data.Buffered$SourceException
	at com.vaadin.ui.Form.commit(Form.java:362)
	at br.com.simus.supera.ciclonev2gui.views.sistema.CadastroUsuarios$2.buttonClick(CadastroUsuarios.java:70)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:487)
	... 21 more
Caused by: com.vaadin.data.Buffered$SourceException
	at com.vaadin.ui.AbstractField.commit(AbstractField.java:247)
	at com.vaadin.ui.Form.commit(Form.java:336)
	... 27 more
Caused by: com.vaadin.data.util.MethodProperty$MethodException
	at com.vaadin.data.util.MethodProperty.invokeSetMethod(MethodProperty.java:748)
	at com.vaadin.data.util.MethodProperty.setValue(MethodProperty.java:702)
	at com.vaadin.ui.AbstractField.commit(AbstractField.java:242)
	... 28 more
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
	at br.com.simus.supera.ciclonev2.persistence.sistema.User.setId(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.vaadin.data.util.MethodProperty.invokeSetMethod(MethodProperty.java:736)
	... 30 more

My Invocation code:


saveButton.addListener(new Button.ClickListener() {            
            @Override
            public void buttonClick(ClickEvent event) {
                form.commit();
                controller.saveUser(usuario);
            }
        });

Many thanks by atention…

Hi all…

I found the source of the problem.

In this form, I have a specialist FieldFactory, that extends DefaultFieldFactory.

In this fieldfactory, I was building the widgets for all fields that I want to pass information. The id of the Entity I dont inform, but the FieldFactory was returning it anyway, and I dont was incluing this on the form, so, I belive that some default value was passed to this property. So, now my FieldFactory only returns the fields that I want, otherwise, it returns null…
Now, all is working, including automatic grid refreshs, etc…

Many thanks!