Hi,
SmartClient Version: SC_SNAPSHOT-2011-03-07/EVAL Deployment
I noticed today that the value of our (behind the scenes) calculation doesn't work anymore.
After investigation, it seems that the FormItemValueParser isn't properly propagating the parsed value to the form!
In our custom Integer editor, the user has the ability to input a simple arithmical function, for instance 12+3.
When the user leaves the field, the arithmical expression is evaluated and calculated and the value should be displayed.
This worked a couple of builds ago!
Also, when tabbing out of the field, the parser is called twice?!?
Which makes no sense to me. This you can also clearly see via the SC.logWarn("REAL VALUE IS: " + integer);
I have added a standalone test case below.
SmartClient Version: SC_SNAPSHOT-2011-03-07/EVAL Deployment
I noticed today that the value of our (behind the scenes) calculation doesn't work anymore.
After investigation, it seems that the FormItemValueParser isn't properly propagating the parsed value to the form!
In our custom Integer editor, the user has the ability to input a simple arithmical function, for instance 12+3.
When the user leaves the field, the arithmical expression is evaluated and calculated and the value should be displayed.
This worked a couple of builds ago!
Also, when tabbing out of the field, the parser is called twice?!?
Which makes no sense to me. This you can also clearly see via the SC.logWarn("REAL VALUE IS: " + integer);
I have added a standalone test case below.
Code:
public class Standalone implements EntryPoint { private static Canvas masterPanel = null; private Button devConsole; /** * * TODO: add description here, do not procrastinate! * * @sofhistory * 9-mrt-2011 bade initial version * * @see com.google.gwt.core.client.EntryPoint#onModuleLoad() * */ public void onModuleLoad() { //masterPanel should be a Layout masterPanel = new Canvas(); masterPanel.setHeight100(); masterPanel.setWidth100(); masterPanel.setStyleName("pageBackground"); //background style from skin DataSource dataSource = new DataSource(); DataSourceField myIntegerField = new DataSourceField(); myIntegerField.setName("inputField"); myIntegerField.setTitle("inputField"); myIntegerField.setType(new MyIntegerItem()); myIntegerField.setEditorType(new MyIntegerEditor()); dataSource.setFields(myIntegerField); DynamicForm form = new DynamicForm(); form.setHeight(170); form.setWidth(500); form.setDataSource(dataSource); masterPanel.addChild(form); masterPanel.draw(); } } public class MyIntegerEditor extends TextItem { public MyIntegerEditor() { super(); this.setChangeOnKeypress(false); // link the formatter to the editor this.setEditorValueFormatter(new MyIntegerValueFormatter()); this.setEditorValueParser(new MyIntegerValueParser()); addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { event.getItem().focusInItem(); } }); } public class MyIntegerValueFormatter implements FormItemValueFormatter { public String formatValue(Object value, Record record, DynamicForm form, FormItem item) { if (value == null) { return ""; } return (String) value; } } public class MyIntegerValueParser implements FormItemValueParser { public Object parseValue(String value, DynamicForm form, FormItem item) { if (value == null || value.length() < 1) return item.getValue(); Integer integer = null; try { integer = new Integer(value); } catch (NumberFormatException ex) { // maybe it's an arithmical function try{ integer = new Integer(calculate(value)); }catch(Exception ignore){ //ignore => bad input, return NULL_INT } } SC.logWarn("REAL VALUE IS: " + integer); return integer; } } public native String calculate(String input) /*-{ var result; result = eval(input); return result == null || result == undefined ? "" : result.toString(); }-*/; }
Comment