Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

DynamicForm.getValues() acts strange with Long values

$
0
0
In a DynamicForm we use some FormItems that have Long values;

Code:

  DynamicForm form = new DynamicForm();
  Long big = 56789012344L;
  Long small = 11L;

  HiddenItem bigLong = new HiddenItem("bigLong");
  bigLong.setValue(big);

  HiddenItem smallLong = new HiddenItem("smallLong");
  smallLong.setValue(small);

  form.setFields(smallLong, bigLong);

The FormItem.setValue(Long longValue) method gets into the setValue(Object x) overload and gets into an if/elseif/... construct.
Because java.lang.Long is a java.lang.Number, we get into the corresponding branch and the value is stored as double into javascript's Number.
Code:

... //SmartGWT code
else if (value instanceof Number) {
            setValue(JSOHelper.doubleValue((Number) value));
...

Which is fine.

However DynamicForm.getValues() returns a LinkedHashMap with unpredictable object types!!!
I expect that if I put a Long in the form, I'd get it back as a Long. I was prepared to loose precision after 2^53 or so, but the change of the value type got me unprepared.

If the original longValue is outside Integer, then the corresponding key holds a Long (as expected) but if the longValue is small, then the corresponding key holds Integer, which breaks our code.

In the above example form.getValues() has an Integer "smallLong" and a Long "bigLong". In particular:
Code:

(Long) form.getValues().get("smallLong");
throws a ClassCastException :(

We are using SmartClient Version: v10.0p_2015-01-26/LGPL Development Only (built 2015-01-26) and the issue is present in all browsers

Viewing all articles
Browse latest Browse all 4756

Trending Articles