Ext-gwt(gxt)TextField getFieldValue()问题

时间:2011-08-04 07:53:20

标签: gwt textfield gxt

我有一个数据类型为Integer的TextField,因此我尝试使用getFieldValue()并将其写入Integer字段。所以在运行时我在这里有一个错误:

TextField<Integer> priceField = new  TextField<Integer>();
Integer newPriceFieldValue = priceField.getValue(); //here is an error in runtime

所以我无法理解最新的问题 - proceField.getValue()应该是Integer,为什么是字符串?也许我应该使用其他类型的Field?

  

java.lang.ClassCastException:java.lang.String无法强制转换为   为java.lang.Integer       在   ru.braginini.client.ProductForm $ 2.componentSelected(ProductForm.java:64)       在   ru.braginini.client.ProductForm $ 2.componentSelected(ProductForm.java:1)

2 个答案:

答案 0 :(得分:3)

如果您希望此字段中只使用数字NumberField可能是更好的选择。

    NumberField field = new NumberField();
    field.setPropertyEditorType(Integer.class);

它将确保只输入数字,并保存一些铸造&amp; getValue()调用的错误处理。

答案 1 :(得分:0)

getValue返回一个String! 您希望将此String分配给导致CastException的Integer(就像在任何面向类型的编程语言中一样。

尝试

Integer newPriceFieldValue = Integer.parseInt(priceField.getValue());

此致 斯蒂芬

相关问题