2012-02-14 96 views
0

我對兩個整數score和numOfQuestions有以下限制。int列拋出的Grails約束約束java.lang.IllegalArgumentException

score blank:false, min:1, nullable:false, notEqual:null 
numOfQuestions blank:false, min:1, nullable:false, notEqual:null 

如可以看出我想這些字段必須大於0,並不能爲空或空白,但無論我做什麼,而不是顯示像一個友好的信息「屬性不能爲空」我屏幕上充滿了很長的例外... 是否有任何其他方式來驗證非空白輸入的整數?

Failed to convert property value of type java.lang.String to required type int for property numOfQuestions; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [int] for property numOfQuestions: PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value of type [null] 

我已經看到了這http://jira.grails.org/browse/GRAILS-4603但並沒有多大幫助

回答

-1

我想你可以替換上面只是約束:

score min:1 
numOfQuestions min:1 

因爲min:1意味着沒有空。約束條件blank: false只能應用於String屬性,所以您對數字屬性使用此約束可能會導致您所看到的異常。

+0

Plus'nullable:false'是默認值,因此指定它是多餘的。 – 2012-02-15 02:37:36

+0

@BurtBeckwith嘿,我不知道爲什麼它不工作,但我得到這個例外,我只有得分:1在約束!無法將類型爲java.lang.String的屬性值轉換爲屬性點所需的類型int;嵌套異常是java.lang.IllegalArgumentException:無法將屬性點的[java.lang.String]類型的值轉換爲所需的類型[int]:PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor]返回類型爲[null ] – Sap 2012-02-29 19:26:15

+0

'score'的變量類型是什麼? – 2012-02-29 21:10:08