In my application I have a need for real big numbers for monetary calculations. There is a BigDecimal for GWT (http://code.google.com/p/gwt-math/) that is supposed to help out on this.

When I edit (change the value) a NumberField I get an exception saying:

[ERROR] Uncaught exception escaped

java.lang.ClassCastException: java.lang.Double cannot be cast to java.math.BigDecimal
at br.com.ierp.gxt.entity.BeanModel_br_com_ierp_gxt_entity_Carteira.set(transient source for br.com.ierp.gxt.entity.BeanModel_br_com_ierp_gxt_entity_Carteira:224)
at com.extjs.gxt.ui.client.store.Record.set(Record.java:287)
at com.extjs.gxt.ui.client.binding.FieldBinding.updateModel(FieldBinding.java:178)
at com.extjs.gxt.ui.client.binding.FieldBinding.onFieldChange(FieldBinding.java:201)
at com.extjs.gxt.ui.client.binding.FieldBinding$1.handleEvent(FieldBinding.java:53)
at com.extjs.gxt.ui.client.binding.FieldBinding$1.handleEvent(FieldBinding.java:1)
at com.extjs.gxt.ui.client.event.BaseObservable.callListener(BaseObservable.java:176)
at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:96)
at com.extjs.gxt.ui.client.widget.Component.fireEvent(Component.java:444)
at com.extjs.gxt.ui.client.widget.form.Field.fireChangeEvent(Field.java:1005)
at com.extjs.gxt.ui.client.widget.form.Field.onBlur(Field.java:1046)
at com.extjs.gxt.ui.client.widget.form.TextField.onBlur(TextField.java:405)
at com.extjs.gxt.ui.client.widget.form.Field.onComponentEvent(Field.java:600)
at com.extjs.gxt.ui.client.widget.Component.onBrowserEvent(Component.java:760)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1320)
at com.google.gwt.user.client.DOM.dispatchEventAndCatch(DOM.java:1299)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1262)
at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:126)
at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155)
at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294)
at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194)
at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966)
at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235)
at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)
One thing to be noticed is that I do NOT get the error when I type any value for the first time (insert), and I also do NOT get any error when I display and populate the grid and fields in the form.

This is the code to set the NumberField to work with the BigDecimal class:

fieldValorPrevistoReal = new NumberField();
fieldValorPrevistoReal.setPropertyEditorType(BigDecimal.class);
Or this one:

fieldValorPrevistoReal = new NumberField();
fieldValorPrevistoReal.setPropertyEditor(new NumberPropertyEditor(BigDecimal.class));Neither of them seem to solve the problem.

Comments anyone? Why is there so little support for Big types when most systems usually have financial data.

Thanx

/Erik

sven

15 Sep 2010, 5:15 AM

GWT does not support BigDecimal. GWT2.1 will add BigDecimal support. NumberFormat (from GWT) accepts a double, that is why we pass a double in.

erikhedb

15 Sep 2010, 8:55 PM

God morning :)

Yes but how do most developer get around this? Just put the head in the sand? We are going with our own solution based on GWT-MATH and modifications of the Gxt classes.

Also - when can we expect support for GWT 2.2? Could not find anything about it in the plans/notes for Gxt.

Thanks /Erik

sven

16 Sep 2010, 1:15 AM

Yes but how do most developer get around this? NumberFormat does not accept anything else than a double as of now. We cannot do anythign about this as this is not a GXT class. Also this is just for displayingthe value.

More relavant should be the part in post #2. We are going to look into things like this when GWT 2.2 moves out of milestone phase.