开发者

Ext-gwt (gxt) TextField getFieldValue() problem

I have an TextField with datatype Integer, so I am trying to getFieldValue() and write it to Integer field. So in runtime I have an error here:

TextField<Integer> priceField = new  TextField<Integer>();
Integer newPriceFieldValue = priceField.getValue(); //here is an error in run开发者_C百科time

So I cant understand whats the problem - proceField.getValue() should be Integer, why string? Maybe I should another type of Field?

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer at ru.braginini.client.ProductForm$2.componentSelected(ProductForm.java:64) at ru.braginini.client.ProductForm$2.componentSelected(ProductForm.java:1)


If you are expecting only numbers to be used in this field NumberField may be the better choice.

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

It will ensure only numbers are entered, and save you some casting & error handling on the getValue() call.


getValue returns a String! You want to assign this String to an Integer which causes an CastException (like it would in any Type oriented Programming language.

Try

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

Regards, Stefan

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜