Hi,
SmartClient Version: SC_SNAPSHOT-2011-01-25/EVAL Deployment
I created this standalone test case, because I believe there are some issues with extending the CheckBoxItem and thus creating our own custom CheckBoxItem.
The initial value of the checkBox is not set correctly, it is always set to the default => "true".
The reason "why" becomes clear as the EditorValueFormatter and EditorValueParser are never called?!?
Something I find very strange, as my other custom editor types don't seem to have a problem with this, however, these other editors extend TextItem or ComboBoxItem.
On the other hand, the input transformer is called! However, as the initial value is not set correctly, my oldValue is a javascriptobject (which I expect it to be) but my (new) value is "true"and not the value after the change?!? In other words, I'm getting the default value from the checkBox iso the clicked event.
I also tried adding a valueMap, but that doesn't fix anything.
My biggest issue is that the formatter or parser are not called.
Please advice.
Regards,
Bart
SmartClient Version: SC_SNAPSHOT-2011-01-25/EVAL Deployment
I created this standalone test case, because I believe there are some issues with extending the CheckBoxItem and thus creating our own custom CheckBoxItem.
The initial value of the checkBox is not set correctly, it is always set to the default => "true".
The reason "why" becomes clear as the EditorValueFormatter and EditorValueParser are never called?!?
Something I find very strange, as my other custom editor types don't seem to have a problem with this, however, these other editors extend TextItem or ComboBoxItem.
On the other hand, the input transformer is called! However, as the initial value is not set correctly, my oldValue is a javascriptobject (which I expect it to be) but my (new) value is "true"and not the value after the change?!? In other words, I'm getting the default value from the checkBox iso the clicked event.
I also tried adding a valueMap, but that doesn't fix anything.
My biggest issue is that the formatter or parser are not called.
Please advice.
Regards,
Bart
Code:
public class Standalone implements EntryPoint { /** * Container for either the login window or the workspace; */ private static Canvas masterPanel = null; public void onModuleLoad() { //masterPanel should be a Layout // this way, it will re-layout its members if the browser gets resized masterPanel = new Canvas(); masterPanel.setHeight100(); masterPanel.setWidth100(); masterPanel.setStyleName("pageBackground"); //background style from skin DataSource dataSource = new DataSource(); DataSourceField myCheckBoxField = new DataSourceField(); myCheckBoxField.setName("checkBoxField1"); myCheckBoxField.setTitle("checkBoxField1"); myCheckBoxField.setType(new MyCheckBoxType()); myCheckBoxField.setEditorType(new MyCheckBoxEditor()); dataSource.setFields(myCheckBoxField); //the order list grid DynamicForm form = new DynamicForm(); form.setHeight(170); form.setWidth(500); form.setDataSource(dataSource); form.setValue("checkBoxField1", createBoolean("false")); masterPanel.addChild(form); masterPanel.draw(); } public static JavaScriptObject createBoolean(String theBool){ JavaScriptObject jsObject = JSOHelper.createObject(); //this is needed for the 'undefined' state if(theBool == null){ JSOHelper.setAttribute(jsObject, "booleanValue", theBool); } else{ JSOHelper.setAttribute(jsObject, "booleanValue", Boolean.parseBoolean(theBool)); } return jsObject; } public static class MyCheckBoxType extends SimpleType { public MyCheckBoxType() { super("myCheckBoxType", FieldType.ANY); } } private class MyCheckBoxEditor extends CheckboxItem { private Boolean booleanValue; public MyCheckBoxEditor() { super(); this.setAllowEmptyValue(true); this.setShowUnsetImage(true); this.setInputTransformer(new MyCheckBoxTransformer()); this.setEditorValueFormatter(new MyCheckBoxEditorFormatter()); this.setEditorValueParser(new MyCheckBoxValueParser()); } public class MyCheckBoxTransformer implements FormItemInputTransformer { @SuppressWarnings("unchecked") public Object transformInput(DynamicForm form, FormItem item, Object value, Object oldValue) { if (value == null) { return item.getValue(); } if(value instanceof Boolean){ return createBoolean(((Boolean) value).toString()); } return createBoolean((String) value); } } public class MyCheckBoxEditorFormatter implements FormItemValueFormatter { public String formatValue(Object value, Record record, DynamicForm form, FormItem item) { if (value == null) return null;//undefined if (value instanceof JavaScriptObject) { JavaScriptObject object = (JavaScriptObject) value; booleanValue = JSOHelper.getAttributeAsBoolean(object, "booleanValue"); return String.valueOf(booleanValue); } return (String) value; } } public class MyCheckBoxValueParser implements FormItemValueParser { public Object parseValue(String value, DynamicForm form, FormItem item) { boolean boolvalue = false; if(value == null || value.length() < 1){ return item.getValue(); } boolvalue = (value.equals("true") || value.equals("1")); JavaScriptObject jsObject = null; if (item.getValue() instanceof JavaScriptObject) { jsObject = (JavaScriptObject) item.getValue(); } if (jsObject == null) return createBoolean(value); JavaScriptObject newJsObject = JSOHelper.createObject(); JSOHelper.setAttribute(newJsObject, "booleanValue", boolvalue); return newJsObject; } } } }
Comment