Smart GWT EE, SC_SNAPSHOT-2010-12-14/EVAL Deployment
Hi,
My problem is the following:
When the value of a certain field is changed, a custom operation needs to be performed. This seems like a trivial thing, just use the ChangedEvent or ItemChangedEvent and call the custom operation from inside.
However, working with my own custom simple types, this seems to take it to another level. What I mean is that I can't get my head around when the framework is triggering these events and the data that is in these events.
The ChangeEvent and ChangeDEvent are called everytime I type something in my formItem?!? Thus will trigger the operation too soon. So, I thought about checking the "event values" before calling my operation.
But the "values" in the events are always the same between all objects in the event?!? See, the code and output below to see what I mean.
Example, code below generates the given output when typing...
The code of the custom editor
Hi,
My problem is the following:
When the value of a certain field is changed, a custom operation needs to be performed. This seems like a trivial thing, just use the ChangedEvent or ItemChangedEvent and call the custom operation from inside.
However, working with my own custom simple types, this seems to take it to another level. What I mean is that I can't get my head around when the framework is triggering these events and the data that is in these events.
The ChangeEvent and ChangeDEvent are called everytime I type something in my formItem?!? Thus will trigger the operation too soon. So, I thought about checking the "event values" before calling my operation.
But the "values" in the events are always the same between all objects in the event?!? See, the code and output below to see what I mean.
Example, code below generates the given output when typing...
Code:
protected class FleetVehicleChangedHandler implements ChangedHandler { public void onChanged(ChangedEvent event) { FormItem source = (FormItem) event.getSource(); FormItem item = event.getItem(); if(event.getValue() != null){ GWT.log("event.value: " + JSOHelper.getAttribute((JavaScriptObject) event.getValue(), SilkString.FIELD_TEXT)); } if(event.getItem() != null){ GWT.log("item.value: " + JSOHelper.getAttribute((JavaScriptObject) item.getValue(), SilkString.FIELD_TEXT)); } if(event.getSource() != null){ GWT.log("source.value: " + JSOHelper.getAttribute((JavaScriptObject) source.getValue(), SilkString.FIELD_TEXT)); } if(!source.getValue().equals(event.getValue())){ parent.performCustomOperation(FineOutpostService.completeIncident); } } } [20110104 08:13:35] event.value: I [20110104 08:13:35] item.value: I [20110104 08:13:35] source.value: I [20110104 08:13:35] event.value: I [20110104 08:13:35] item.value: I [20110104 08:13:35] source.value: I [20110104 08:13:35] event.value: I a [20110104 08:13:35] item.value: I a [20110104 08:13:35] source.value: I a [20110104 08:13:35] event.value: I am [20110104 08:13:35] item.value: I am [20110104 08:13:35] source.value: I am [20110104 08:13:36] event.value: I am [20110104 08:13:36] item.value: I am [20110104 08:13:36] source.value: I am [20110104 08:13:36] event.value: I am t [20110104 08:13:36] item.value: I am t [20110104 08:13:36] source.value: I am t [20110104 08:13:37] event.value: I am ty [20110104 08:13:37] item.value: I am ty [20110104 08:13:37] source.value: I am ty [20110104 08:13:37] event.value: I am typ [20110104 08:13:37] item.value: I am typ [20110104 08:13:37] source.value: I am typ [20110104 08:13:37] event.value: I am typi [20110104 08:13:37] item.value: I am typi [20110104 08:13:37] source.value: I am typi [20110104 08:13:37] event.value: I am typin [20110104 08:13:37] item.value: I am typin [20110104 08:13:37] source.value: I am typin [20110104 08:13:38] event.value: I am typing [20110104 08:13:38] item.value: I am typing [20110104 08:13:38] source.value: I am typing [20110104 08:13:38] event.value: I am typing [20110104 08:13:38] item.value: I am typing [20110104 08:13:38] source.value: I am typing [20110104 08:13:38] event.value: I am typing s [20110104 08:13:38] item.value: I am typing s [20110104 08:13:38] source.value: I am typing s [20110104 08:13:38] event.value: I am typing so [20110104 08:13:38] item.value: I am typing so [20110104 08:13:38] source.value: I am typing so [20110104 08:13:38] event.value: I am typing som [20110104 08:13:38] item.value: I am typing som [20110104 08:13:38] source.value: I am typing som [20110104 08:13:38] event.value: I am typing some [20110104 08:13:38] item.value: I am typing some [20110104 08:13:38] source.value: I am typing some [20110104 08:13:39] event.value: I am typing somet [20110104 08:13:39] item.value: I am typing somet [20110104 08:13:39] source.value: I am typing somet [20110104 08:13:39] event.value: I am typing someth [20110104 08:13:39] item.value: I am typing someth [20110104 08:13:39] source.value: I am typing someth [20110104 08:13:39] event.value: I am typing somethi [20110104 08:13:39] item.value: I am typing somethi [20110104 08:13:39] source.value: I am typing somethi [20110104 08:13:39] event.value: I am typing somethin [20110104 08:13:39] item.value: I am typing somethin [20110104 08:13:39] source.value: I am typing somethin [20110104 08:13:39] event.value: I am typing something [20110104 08:13:39] item.value: I am typing something [20110104 08:13:39] source.value: I am typing something [20110104 08:13:39] event.value: I am typing something [20110104 08:13:39] item.value: I am typing something [20110104 08:13:39] source.value: I am typing something
Code:
public class SilkStringEditor extends TextItem { private String text; public SilkStringEditor() { super(); // link the formatter to the editor this.setEditorValueFormatter(new SilkStringValueFormatter()); this.setEditorValueParser(new SilkStringValueParser()); } public class SilkStringValueFormatter implements FormItemValueFormatter { public String formatValue(Object value, Record record, DynamicForm form, FormItem item) { if (value == null) return SilkDBConstants.NULL_STRING; if (value instanceof JavaScriptObject) { JavaScriptObject object = (JavaScriptObject) value; text = JSOHelper.getAttribute(object, SilkString.FIELD_TEXT); return text; } return (String) value; } } public class SilkStringValueParser implements FormItemValueParser { public Object parseValue(String value, DynamicForm form, FormItem item) { JavaScriptObject jsObject = (JavaScriptObject) item.getValue(); if(jsObject == null) return createJSObject(value); JavaScriptObject newJsObject = SilkJSOHelper.clone(jsObject); JSOHelper.setAttribute(newJsObject, SilkString.FIELD_TEXT, value); return newJsObject; } } }
Comment