2012-10-16 83 views
0

將包含整數屬性的bean綁定到窗體時,當顯示窗體時,該字段的值爲0,這是正常的,因爲這是整數默認值。 但是當我刪除字段的0,並把重點放在下一個表單字段(setImmediate =真),我得到一個討厭的例外:Vaadin窗體綁定異常

com.vaadin.data.Property$ConversionException: java.lang.reflect.InvocationTargetException 
    at com.vaadin.data.util.MethodProperty.convertValue(MethodProperty.java:695) 
    at com.vaadin.data.util.MethodProperty.setValue(MethodProperty.java:664) 
    at com.vaadin.ui.AbstractField.setValue(AbstractField.java:495) 
    at com.vaadin.ui.AbstractTextField.changeVariables(AbstractTextField.java:242) 
    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: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:291) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) 
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
    at java.lang.reflect.Constructor.newInstance(Unknown Source) 
    at com.vaadin.data.util.MethodProperty.convertValue(MethodProperty.java:692) 
    ... 22 more 
Caused by: java.lang.NumberFormatException: For input string: "" 
    at java.lang.NumberFormatException.forInputString(Unknown Source) 
    at java.lang.Integer.parseInt(Unknown Source) 
    at java.lang.Integer.<init>(Unknown Source) 
    ... 27 more 

我當然可以通過設置字段作爲必需避免這種情況但那不是我想要的。我對Vaadin相當陌生,所以我錯過了什麼?

謝謝

+0

它看起來像,你期待一個數字,但系統給你一個字符串回來(似乎是空字符串),它不能被轉換爲數字。 – Jaiwo99

+0

嘗試使用'Integer'而不是'int'來綁定您的數字字段。沒有主類型,但Object!嘗試從表單中向我們展示一些代碼。 – Jaiwo99

回答

0

也許使用整數包裝和textField.setNullRepresentation( 「」);將幫助

+0

這是一種可能性,但它意味着你必須調整你的bean的所有數值(int或float)屬性。這是我想避免 – user1469130

+0

這不應該是解決方案,如果TextField得到一個值'null',它也顯示'「null」' – Jaiwo99