將包含整數屬性的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相當陌生,所以我錯過了什麼?
謝謝
它看起來像,你期待一個數字,但系統給你一個字符串回來(似乎是空字符串),它不能被轉換爲數字。 – Jaiwo99
嘗試使用'Integer'而不是'int'來綁定您的數字字段。沒有主類型,但Object!嘗試從表單中向我們展示一些代碼。 – Jaiwo99