Hi everybody,
I am using SmartGwt 2.4 with firefox 3.6.18.
I set the locale to it in the meta tag of my page and I am sure it works.
I would like to have a comma as decimal separator when showing and editing TreeGrid fields of type float.
In the TreeGrid I have an editable field that is created like this:
This is the console log (debug level) when setting the field value to 10,55
when I get the server data prices appears in the correct format, say 10,55, with a comma as decimal separator, which is what I want. When I double click to edit it, I correctly get a textfield with 10,55, still showing a comma. But when I finish editing pressing the Enter button I get a validation message saying that the my price format is not correct.
If I write 10.55 instead of 10,55 the value is accepted and when I finish editing I see 10,55.
I have seen that if I comment out the call to setEditValueFormatter when I start editing I get 10.55, with a dot instead of the expected comma.
I don't understand what I am missing. Maybe I should disable the default validators. How? I would like to always see and digit commas as decimal separartors.
Thanks in advance for your help.
regards Francesco Milesi
I am using SmartGwt 2.4 with firefox 3.6.18.
I set the locale to it in the meta tag of my page and I am sure it works.
I would like to have a comma as decimal separator when showing and editing TreeGrid fields of type float.
In the TreeGrid I have an editable field that is created like this:
Code:
priceField = new TreeGridField(fields.price(), 150); priceField.setType(ListGridFieldType.FLOAT); priceField.setCellFormatter(new CellFormatter() { @Override public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if(value == null) return null; NumberFormat nf = NumberFormat.getFormat("#,##0.00"); try { return nf.format(((Number)value).floatValue()); } catch (Exception e) { return value.toString(); } } }); priceField.setEditValueFormatter(new CellEditValueFormatter() { @Override public Object format(Object value, ListGridRecord record, int rowNum, int colNum) { Double d = null; if(value == null) return null; if(value instanceof Float) { String stringValue = null; NumberFormat nf = NumberFormat.getFormat("#,##0.00"); try { stringValue = nf.format((Float) value); } catch (Exception e) { return value.toString(); } return stringValue; } else { NumberFormat nf = NumberFormat.getFormat("#,##0.00"); try { d = nf.parse(value.toString()); } catch (Exception e) { return value.toString(); } return d.floatValue(); } } });
Code:
00:34:24.213:TMR6:INFO:gridEdit:isc_MenuTreeGrid_0:Starting editing at row 3, colNum 1 00:34:24.214:TMR6:INFO:gridEdit:isc_MenuTreeGrid_0:establishing new edit session at row: 3, col:1 with values: {} 00:34:24.266:TMR6:DEBUG:gridEdit:isc_MenuTreeGrid_0:showing inline editor at: 3,1, will focus: true 00:34:28.516:KPR7:INFO:gridEdit:isc_MenuTreeGrid_0:cellEditEnd: ending editing, completion event: enter 00:34:28.522:KPR7:DEBUG:gridEdit:isc_MenuTreeGrid_0:change detection: newValues: {id: -343, price: "10,55"}, oldValues: {id: 343, description: "dish1", name: "dish1", index: 1, isFolder: false, parentId: 166, price: 55.33, } 00:34:28.525:KPR7:DEBUG:gridEdit:isc_MenuTreeGrid_0:At field: price applying validators: [ {type: "isFloat", typeCastValidator: true, _generated: true, defaultErrorMessage: "Deve essere un decimale valido.", (NDT: It must be a valid decimal....) resultingValue: undef} ] to value:10,55 00:34:28.527:KPR7:INFO:gridEdit:isc_MenuTreeGrid_0:validateFieldValue, newValue: "10,55", passed validation: false, resultingValue: null
If I write 10.55 instead of 10,55 the value is accepted and when I finish editing I see 10,55.
I have seen that if I comment out the call to setEditValueFormatter when I start editing I get 10.55, with a dot instead of the expected comma.
I don't understand what I am missing. Maybe I should disable the default validators. How? I would like to always see and digit commas as decimal separartors.
Thanks in advance for your help.
regards Francesco Milesi
Comment