Conversion error while committing comboBox value to SQLContainer

hey,

I have been trying the SQLContainer tutorial. Trying to save a person after picking up a city from a drop down list throws an error:

18:16:10,324 SEVERE [com.vaadin.server.DefaultErrorHandler]
(default task-12) : com.vaadin.data.Buffered$SourceException
at com.vaadin.ui.AbstractField.setValue(AbstractField.java:517) [vaadin-server-7.3.10.jar:7.3.10]

at com.vaadin.ui.AbstractSelect.setValue(AbstractSelect.java:702) [vaadin-server-7.3.10.jar:7.3.10]

at com.vaadin.ui.ComboBox.changeVariables(ComboBox.java:674) [vaadin-server-7.3.10.jar:7.3.10]

at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:485) [vaadin-server-7.3.10.jar:7.3.10]

at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:301) [vaadin-server-7.3.10.jar:7.3.10]

at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:180) [vaadin-server-7.3.10.jar:7.3.10]

at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:93) [vaadin-server-7.3.10.jar:7.3.10]

at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41) [vaadin-server-7.3.10.jar:7.3.10]

at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1406) [vaadin-server-7.3.10.jar:7.3.10]

at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305) [vaadin-server-7.3.10.jar:7.3.10]

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

at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.websockets.jsr.JsrWebSocketFilter.doFilter(JsrWebSocketFilter.java:129) [undertow-websockets-jsr-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166) [undertow-servlet-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759) [undertow-core-1.1.0.Final.jar:1.1.0.Final]

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_31]

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_31]

at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_31]

Caused by: com.vaadin.data.util.converter.Converter$ConversionException: Could not convert value to Integer
at com.vaadin.ui.AbstractField.convertToModel(AbstractField.java:748) [vaadin-server-7.3.10.jar:7.3.10]

at com.vaadin.ui.AbstractField.convertToModel(AbstractField.java:725) [vaadin-server-7.3.10.jar:7.3.10]

at com.vaadin.ui.AbstractField.setValue(AbstractField.java:508) [vaadin-server-7.3.10.jar:7.3.10]

... 41 more

Caused by: com.vaadin.data.util.converter.Converter$ConversionException: Unable to convert value of type com.vaadin.data.util.sqlcontainer.RowId to model type class java.lang.Integer. No converter is set and the types are not compatible.
at com.vaadin.data.util.converter.ConverterUtil.convertToModel(ConverterUtil.java:181) [vaadin-server-7.3.10.jar:7.3.10]

at com.vaadin.ui.AbstractField.convertToModel(AbstractField.java:745) [vaadin-server-7.3.10.jar:7.3.10]

... 43 more

I have been fighting with for two days, and cannot figure out. Please help?

Seems like RowId of your SQLContainer is not Integer (a type of your comboBox value) as error states:
“Unable to convert value of type com.vaadin.data.util.sqlcontainer.RowId to model type class java.lang.Integer. No converter is set and the types are not compatible.”
You need some explicit conversion for this field (perhaps using field’s setConverter method and writing your own converter). Or use another container that is indexed with Integers.

Did you resolve the Conversion error using Combobox from SQL Container? I have the same issue…

Yes, I have written a Converter, IntegerToRowId. (Apparently SQLConverter is not indexed with integer values).

Can you share the complete code? I have a SQL container (selecting from my codes table - code and text - which are BigDecimal and String respectively) populating a combobox in a Fieldgroup. Combobox populates, but when i try to commit the selected value i get the error…

You create a custom converter extending Converter class to convert between model and presentation

  • in my case it was Integer to RowID, so this is how it looked

public Integer convertToModel(RowId value, Class<? extends Integer> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (value == null) return null;
return Integer.valueOf(value.toString());
}

public RowId convertToPresentation(Integer value, Class<? extends RowId> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (value == null) return null;
return new RowId(value);
}

and add it to your comboBox:
comboBox.setConverter((Converter)new IntegerToRowIDConverter())

Thanks. Do you mean extend or implement? Can you share your customer converter class (in its entirety)?