Hello,
I am using SmartGWT 3.0 (but the developer console shows SmartClient Version: 8.2/LGPL Development Only (built 2011-12-05)), GWT 2.4 and Firefox 11.0
I have a TextItem with an EditorValueParser and EditorValueFormatter. The TextItem receives a long value (a timestamp) and it should represent it as a double value (hours). It is working very well when the long value comes directly from the server and value is represented as it should be in hours. But when the user types in the TextItem the value 999 after validation the value that appears in the TextItem is 999.0000355555555. This is just an example how to reproduce the problem.
In fact the problem is that the value returned by the parser (e.g long 144000000) is not the same as the one received by the formater (e.g long 1440000128) and i can not figure out why the underlying value is altered .
Here is a sample that reproduces the problem. Keep in mind that only for certain values is reproduced (e.g. 999, 10000)
I am using SmartGWT 3.0 (but the developer console shows SmartClient Version: 8.2/LGPL Development Only (built 2011-12-05)), GWT 2.4 and Firefox 11.0
I have a TextItem with an EditorValueParser and EditorValueFormatter. The TextItem receives a long value (a timestamp) and it should represent it as a double value (hours). It is working very well when the long value comes directly from the server and value is represented as it should be in hours. But when the user types in the TextItem the value 999 after validation the value that appears in the TextItem is 999.0000355555555. This is just an example how to reproduce the problem.
In fact the problem is that the value returned by the parser (e.g long 144000000) is not the same as the one received by the formater (e.g long 1440000128) and i can not figure out why the underlying value is altered .
Here is a sample that reproduces the problem. Keep in mind that only for certain values is reproduced (e.g. 999, 10000)
Code:
public class Test extends Window { private TextItem workItem; private DynamicForm updateworkForm; public Test() { super(); workItem = new TextItem(); workItem.setTitle("Work"); workItem.setEditorValueFormatter(new FormItemValueFormatter() { @Override public String formatValue(Object value, Record record, DynamicForm form, FormItem item) { if (value != null) { if (value instanceof Number) { long work = ((Number) value).longValue(); return (work / (1000d * 60 * 60)) + ""; } else { return null; } } else { return null; } } }); workItem.setEditorValueParser(new FormItemValueParser() { @Override public Object parseValue(String value, DynamicForm form, FormItem item) { if (value != null) { String integerPartString = ""; String fractionaryPartString = ""; int pointPos = value.indexOf("."); if (pointPos < 0) { integerPartString = value.substring(0, value.length()); } else if (pointPos == 0) { return null; } else { integerPartString = value.substring(0, pointPos); if (value.indexOf(".", pointPos + 1) == -1) { fractionaryPartString = value.substring( pointPos + 1, value.length()); } else { return null; } } long integerPart = 0; long fractionaryPart = 0; if (!integerPartString.equals("")) { integerPart = Long.parseLong(integerPartString) * 1000 * 60 * 60; } if (!fractionaryPartString.equals("")) { fractionaryPart = (long) (Double .parseDouble(fractionaryPartString) / Math.pow(10, value.length() - pointPos - 1) * 1000 * 60 * 60); } long number = integerPart + fractionaryPart; if (number <= Integer.MAX_VALUE) { return new Integer(number + ""); } else { return new Long(number); } } return null; } }); updateworkForm = new DynamicForm(); updateworkForm.setFields(workItem); this.addItem(updateworkForm); this.setWidth(500); this.setHeight(500); } }
Comment