Using Combobox to assign association

Hi guys!

I have a FORM with a ComboBox inside.

The combobox has a DataSourceContainer (JPAContainer) to list my Countries.

The Form has a JPAContainerItem (Person) setted by setItemDataSource.

The Person pojo has an attribute country associated to the Contry pojo.

Now, what I want to do:

  • Use the combobox to select/associate a Country to the Person.

I already created a custom FieldFactory to instantiate my ComboBox for list Countries.

The problems:

  • The combobox doesn’t display the current assigned to the person
  • An exception occurrs on select the country:

com.vaadin.data.Buffered$SourceException
	at com.vaadin.ui.AbstractField.setValue(AbstractField.java:543)
	at com.vaadin.ui.AbstractSelect.setValue(AbstractSelect.java:674)
	at com.vaadin.ui.Select.changeVariables(Select.java:657)
	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:722)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:662)
Caused by: com.vaadin.data.Property$ConversionException: java.lang.NoSuchMethodException: br.com.jjw.suporteweb.model.Country.<init>(java.lang.String)
	at com.vaadin.addon.jpacontainer.JPAContainerItem$ItemProperty.setValue(JPAContainerItem.java:277)
	at com.vaadin.ui.AbstractField.setValue(AbstractField.java:535)
	... 25 more
Caused by: java.lang.NoSuchMethodException: br.com.jjw.suporteweb.model.Sistema.<init>(java.lang.String)
	at java.lang.Class.getConstructor0(Class.java:2706)
	at java.lang.Class.getConstructor(Class.java:1657)
	at com.vaadin.addon.jpacontainer.JPAContainerItem$ItemProperty.setValue(JPAContainerItem.java:271)

It would seem that your Sistema class doesn’t have a no-arg constructor, which is required by the JPA specification. The JPAContainer uses reflection to create instances of your pojo, and that operation fails because no valid constructor exists.

Or maybe Sistema or Country is missing a constructor that takes a String as a parameter and one would be needed for conversions when setting a value of another type for the property - just guessing from the stack trace.