Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SimpleType.setEditorType() problem

    Hi,
    I can't get the following example to work. Basically I want to create SimpleType for displaying AND EDITING numbers according to local format. There is no problem with displaying thanks to SimpleType.setNormalDisplayFormatter(), but am not able to get the same format while editing (both grid and form).
    I can create FormItem with setEditorValueFormatter() and setEditorValueParser() and then use ListGrid.setEditorType() and DynamicForm.setEditorType() which works, but according to the docs I should be able to use SimpleType.setEditorType() instead.
    Unfortunately I got an error here:
    amountType.setEditorType(new FloatItem());
    Code:
    package org.yournamehere.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.i18n.client.NumberFormat;
    import com.smartgwt.client.core.DataClass;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.SimpleType;
    import com.smartgwt.client.data.SimpleTypeFormatter;
    import com.smartgwt.client.data.fields.DataSourceIntegerField;
    import com.smartgwt.client.types.DSDataFormat;
    import com.smartgwt.client.types.FieldType;
    import com.smartgwt.client.widgets.DataBoundComponent;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.FloatItem;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class MainEntryPoint implements EntryPoint {
        
        public MainEntryPoint() {
        }
        
        public void onModuleLoad() {
    
            final NumberFormat amountFormat = NumberFormat.getFormat("###,###.###");
    
            SimpleType amountType = new SimpleType("amount", FieldType.FLOAT);
            amountType.setNormalDisplayFormatter(new SimpleTypeFormatter() {
    
                @Override
                public String format(Object value, DataClass field,
                        DataBoundComponent component, Record record) {
                    return amountFormat.format(Double.valueOf(value.toString()));
                }
            });
            amountType.setShortDisplayFormatter(new SimpleTypeFormatter() {
    
                public String format(Object value, DataClass field,
                        DataBoundComponent component, Record record) {
                    return amountFormat.format(Double.valueOf(value.toString()));
                }
            });
            amountType.setEditorType(new FloatItem()); //error
            amountType.register();
    
            DataSource ds = new DataSource();
            ds.setDataFormat(DSDataFormat.XML);
            ds.setRecordXPath("/List/country");
            ds.setDataURL("data.xml");
    
            DataSourceIntegerField pkField = new DataSourceIntegerField("pk");
            pkField.setHidden(true);
            pkField.setPrimaryKey(true);
    
            DataSourceField areaField = new DataSourceField();
            areaField.setName("area");
            areaField.setType(amountType);
    
            ds.setFields(pkField, areaField);
    
            ListGrid grid = new ListGrid();
            grid.setWidth(300);
            grid.setCanEdit(true);
            grid.setDataSource(ds);
            grid.filterData();
    
            grid.setDataSource(ds);
            grid.filterData();
    
            final DynamicForm form = new DynamicForm();
            form.setDataSource(ds);
            form.fetchData();
    
            VLayout main = new VLayout();
            main.addMember(grid);
            main.addMember(form);
            main.draw();
        }
    }
    00:07:12,486 [ERROR] Unable to load module entry point class org.yournamehere.client.MainEntryPoint (see associated exception for details)
    com.google.gwt.core.client.JavaScriptException: (TypeError): className.startsWith is not a function fileName: http://localhost:8080/TestSimpleType/sc/client/widgets/form/FormItemFactory.js lineNumber: 78 stack: ([object Object])@http://localhost:8080/TestSimpleType/sc/client/widgets/form/FormItemFactory.js:78 ([object Object],[object Object])@http://localhost:8080/TestSimpleType/sc/client/widgets/form/DynamicForm.js:1704 ([object Array],null,true,true)@http://localhost:8080/TestSimpleType/sc/client/widgets/form/DynamicForm.js:1594 ([object Array],true)@http://localhost:8080/TestSimpleType/sc/client/widgets/form/DynamicForm.js:1430 ([object Object],(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0))@http://localhost:8080/TestSimpleType/sc/client/widgets/form/DynamicForm.js:1290 ([object Object],(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0))@http://localhost:8080/TestSimpleType/sc/client/widgets/Canvas.js:2581 ([object Object],(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0),(void 0))@http://localhost:8080/TestSimpleType/sc/client/language/Class.js:1627 ([object Object])@http://localhost:8080/TestSimpleType/sc/client/language/Class.js:135 ()@http://localhost:8080:450 @:0 ([object GWTJavaObject],2556055)@http://localhost:8080/TestSimpleType/hosted.html?org_yournamehere_Main:56 ()@http://localhost:8080:290 connect("http://localhost:8080/TestSimpleType/?gwt.codesvr=127.0.0.1:9997","Ojn)`ssFd/?))vd~","127.0.0.1:9997","org.yournamehere.Main","2.0")@:0 ((void 0),"org.yournamehere.Main","http://localhost:8080/TestSimpleType/")@http://localhost:8080/TestSimpleType/hosted.html?org_yournamehere_Main:264 z()@http://localhost:8080/TestSimpleType/org.yournamehere.Main.nocache.js:2 (-6)@http://localhost:8080/TestSimpleType/org.yournamehere.Main.nocache.js:11 at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:195) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:284) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107) at com.smartgwt.client.widgets.form.DynamicForm.fetchData(DynamicForm.java) at org.yournamehere.client.MainEntryPoint.onModuleLoad(MainEntryPoint.java:74) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:369) at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:185) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:380) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222) at java.lang.Thread.run(Thread.java:619)

    Thanks for help.
    MichalG
    ps SmartGWT svn 1116, GWT2

    #2
    We created a custom SimpleType, registered it, linked it to a datasourcefield (XML datasource, so using type="simpletype"). We also created a custom editor (extends TextItem), and used setEditorType to link it to the SimpleType.
    Our DataSource is used for a ListGrid.
    Formatting the listgrid field works fine.

    We encountered two problems regarding SimpleType usage for editing:

    1. Wrong implementation for SimpleType.setEditorType (causing exception as stated in previous post):

    Current:

    Code:
    setAttribute("editorType", editorType, false);
    Should be (?):

    Code:
    setAttribute("editorType", formItem.getType(), false);
    JavaScriptObject editorConfig = formItem.getConfig();
    setAttribute("editorProperties", editorConfig, false);
    2. When using above implementation, still no luck: format(...) of the SimpleTypeFomatter gets called rather than the FormItemValueFormatter.format(...). It is by the way called with Canvas as DataBoundComponent parameter, instead of DynamicForm (which extends Canvas), causing a ClassCastException (Canvas is not a DataBoundComponent).

    Is this the way it's supposed to be set up?
    Did anyone succeed in creating custom editors for grids this way?
    Last edited by hin3x; 9 Jun 2010, 07:33.

    Comment


      #3
      What version are you talking about? (always include this)

      Currently the setEditorType() API at the DataSource and SimpleType level is only capable of handling editors that involve some simple property settings and event handler registrations, not subclasses that involve method overrides. However, setEditorType() at the ListGrid level is fully functional.

      Comment


        #4
        We are evaluating SmartGWTEE (nightly build from 8th of June, but it was there all along I guess) and are trying to build an architecture (as a 'proof of concept' for SmartGWT technology) where we want everything to be initiated/generated/'pushed' server side, leaving the 'presentation' for the client.
        It involves generating datasources on the fly, based on (dynamic) metadata. We want to link our custom types (currency, distance, duration, ....), including validators and the like, to a dedicated formatter/editor, just by linking the datasource to the listgrid.

        In fact what you're saying now is that although the formatter works, for the editor we need to reevaluate the datasourcefield type at client side and link the custom editor to the appropriate listgridfield?
        That involves a client side conversion (we don't want, hence looking at the server side datasources and all).

        Will this be fixed as 'bug' or is it considered a 'known issue' to be fixed by feature sponsorship? It looks to me that it is almost working, or am I mistaken?

        Or isn't this the way to go? Is there another solution/workaround?
        Last edited by hin3x; 10 Jun 2010, 00:28.

        Comment


          #5
          We do want to enhance this so the DataSource / SimpleType API allows arbitrary editorTypes, and it is something you can sponsor. Bear in mind however, a custom ListGrid subclass could also detect some custom attribute added to your DataSource and use that to call setEditorType() on the ListGridField.

          Comment


            #6
            Hi Isomorphic,

            I'm now getting this same Class Cast Exception as well!
            Is this a bug that you guys are working on?

            If not, then I'll have to figure out how I'm going to make my simpletypes work with an editable ListGrid :-(

            -------------------------------------------------------------------------------------------------------

            [30/06/2010] The workaround suggested above does work.
            Last edited by bade; 29 Jun 2010, 21:39.

            Comment


              #7
              hi
              Can somebody explain the workaround please?
              Thanks!

              Comment


                #8
                Please does anybody knows how to subclass ListGrid and DynamicForm for detect customs types and add custom formatters?
                Thank you!

                Comment

                Working...
                X