Announcement

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

    re-adding custom formitem gives error on isDisabled

    Hello,

    I'm creating a custom Dynamic Form, attached an enterprise Datasource to it which consists of fields with custom types and editors.
    After setting the datasource, I do getFields on the Form and create a new array of only items I want in the form and in the order I want them to be. (sidequestion: I noted here that I don't get the right class of the items via getFields, they are all of class FormItem instead of TextItem, ComboboxItem, ... is that normal?)


    When setting those items back onto the form I get the following error. I've been searching for such a "destroyed" item and with the help of the stacktrace, I found that the items that give this error are only my custom items: they do have an icon, but it's not disabled. And this procedure does work for all other items not having such an icon.

    Any hints on where to search for the cause of this error? Thanks.


    Attached is a log of the FormItem as jsObject and the JS stacktrace.

    Code:
    [20100907 09:24:04] 09:24:04.463:MUP5:WARN:Log:TextItem{eventParent: [DynamicForm ID:isc_zzzDynamicForm_1],
    containerWidget: [DynamicForm ID:isc_zzzDynamicForm_1],
    form: [DynamicForm ID:isc_zzzDynamicForm_1],
    crud: "15",
    javaClass: "zzz.parameter.zzzMCurrency",
    name: "amount",
    required: true,
    zzzId: "1216",
    title: "Amount",
    type: "zzzMCurrency",
    validators: Array[2],
    editorType: "TextItem",
    editorProperties: Obj,
    iconPrompt: "Change value",
    selectOnFocus: true,
    icons: Array[1],
    ID: "isc_TextItem_2",
    prompt: "amount",
    }
    
    
    [20100907 09:24:04] 09:24:04.484:MUP5:WARN:DynamicForm:isc_zzzDynamicForm_1:destroyed FormItem passed to setItems()/addItem(): FormItems cannot be re-used with different DynamicForms
    
    
    
    com.google.gwt.core.client.JavaScriptException: (TypeError): Cannot call method 'isDisabled' of null
     stack: TypeError: Cannot call method 'isDisabled' of null
        at Object.isc_FormItem_isDisabled [as isDisabled] (http://127.0.0.1:8888/zzz/sc/modules/ISC_Forms.js:1414:84)
        at Object.isc_FormItem_iconIsDisabled [as iconIsDisabled] (http://127.0.0.1:8888/zzz/sc/modules/ISC_Forms.js:1423:213)
        at Object.isc_FormItem__setUpIcon [as $36c] (http://127.0.0.1:8888/zzz/sc/modules/ISC_Forms.js:1048:72)
        at Object.isc_FormItem__setUpIcons [as $14v] (http://127.0.0.1:8888/zzz/sc/modules/ISC_Forms.js:1047:133)
        at Object.isc_FormItem_init (http://127.0.0.1:8888/zzz/sc/modules/ISC_Forms.js:782:138)
        at Object.isc_c_Class_invokeSuper [as invokeSuper] (http://127.0.0.1:8888/zzz/sc/modules/ISC_Core.js:301:76)
        at Object.isc_c_Class_Super [as Super] (http://127.0.0.1:8888/zzz/sc/modules/ISC_Core.js:293:157)
        at Object.isc_TextItem_init [as init] (http://127.0.0.1:8888/zzz/sc/modules/ISC_Forms.js:1778:47)
        at Object.isc_Class_completeCreation [as completeCreation] (http://127.0.0.1:8888/zzz/sc/modules/ISC_Core.js:360:6)
        at Object.isc_DynamicForm_createItem [as createItem] (http://127.0.0.1:8888/zzz/sc/modules/ISC_Forms.js:302:84)
     type: non_object_property_call
     arguments: isDisabled,
     __gwt_ObjectId: 2643
    SmartGWT 2.3 EE
    SmartClient Version: SC_SNAPSHOT-2010-08-03/EVAL Deployment (expires 2010.10.02_09.35.33)

    #2
    You can't take the generated items and apply them via setItems(). Instead, if you need to dynamically provide items based on the DataSource, iterate over DataSourceFields (*not* the items generated from them) and supply your own items via setItems().

    Comment


      #3
      Ok thanks for the suggestion.
      Is the default "DataSourceField to FormItem" (and to ListGridField) implementation exposed somewhere to fallback to?
      Last edited by levi; 8 Sep 2010, 09:38.

      Comment


        #4
        Not at the moment, but it's very trivial and explained in the docs for getEditorType().

        Comment


          #5
          I'm trying to do a similar thing but spreading a data source through different tabs. I dynamically allocate the data source fields in the ds.xml file into multiple DynamicForms (which I call setDataSource() with the same data source on each) and then consolidate with a ValuesManager. However, I keep getting the warning about destroyed items.

          I think this is the solution I'm looking for but I'm using SmartGWT EE 2.3 and I don't see DataSourceField.getEditorType(). Am I missing something?

          Assuming if I could get the EditorType from the DataSourceField, would I then do something like...
          Code:
          DataSourceField dsField = DataSource.get("myDs").getField("myField");
          FormItem formItem = new FormItem();
          formItem.setEditorType(dsField.getEditorType());
          
          DynamicForm form = new DynamicForm();
          form.setItems(formItem);
          Thanks!

          Comment


            #6
            It looks like FormEditor.setEditorType() takes a FormItem for an argument but the documentation suggests something else:

            Name of the FormItem to use for editing, eg "TextItem" or "SelectItem".
            The type of FormItem to use for editing is normally derived automatically from type, which is the data type of the field, by the rules explained here.

            Parameters:
            editorType editorType Default value is null

            Comment


              #7
              Check the latest builds, more detail has been added as far as how to use this API.

              If you're still seeing docs like you quoted in the latest build, please indicate exactly where.

              Comment


                #8
                I downloaded the 9-28-10 SmartGWT EE 2.3 build and this is what FormItem.setEditorType(FormItem editorType) says in the javadoc...

                "Name of the FormItem properties to use for editing.

                The type of FormItem to use for editing is normally derived automatically from type, which is the data type of the field, by the rules explained here.


                Note : When you supply a custom FormItem via setEditorType(), you're really providing properties which are then used to create multiple FormItems (eg, in grids, forms and trees) and there's an underlying limitation here where event handlers have to be written to dynamically receive the actual FormItem rather than relying on "this" (because there's more than one "this").

                Parameters:
                editorType editorType Default value is null"


                I'm still not sure how to use FormItem.setEditorType(). Especially since DataSourceField.getEditorType() returns a string. Any help would be appreciated. Thanks!

                Comment


                  #9
                  OK, that API (FormItem.setEditorType()) really isn't needed in SmartGWT and we may remove it to avoid confusion. Instead, create the FormItem you want to use and pass it to DataSourceField.setEditorType(). This will cause it to be used in DynamicForm, ListGrid, TreeGrid and other editable components.

                  But be sure to read the docs for DataSourceField.setEditorType() in the latest build, which has been updated to explain how to write event handlers when using this API.

                  Comment


                    #10
                    Originally posted by kevboy
                    I'm trying to do a similar thing but spreading a data source through different tabs. I dynamically allocate the data source fields in the ds.xml file into multiple DynamicForms (which I call setDataSource() with the same data source on each) and then consolidate with a ValuesManager. However, I keep getting the warning about destroyed items.

                    I think this is the solution I'm looking for but I'm using SmartGWT EE 2.3 and I don't see DataSourceField.getEditorType(). Am I missing something?

                    Assuming if I could get the EditorType from the DataSourceField, would I then do something like...
                    Code:
                    DataSourceField dsField = DataSource.get("myDs").getField("myField");
                    FormItem formItem = new FormItem();
                    formItem.setEditorType(dsField.getEditorType());
                    
                    DynamicForm form = new DynamicForm();
                    form.setItems(formItem);
                    Thanks!
                    As posted above, I wanted to create FormItems using the specification in a data source ds.xml file. Seems like the method you suggested is kind of, opposite as it would update a data source's field to use a specified FormItem type (editor type).

                    If there's a better way to achieve separation of fields into multiple forms without getting the "item already destroyed" warnings, I would be greatly appreciative to learn of it.

                    By the way, thanks for your quick replies!

                    Comment


                      #11
                      Can you give a bigger picture of what you're trying to do? If you just bind forms to DataSources and specify items via setItems() where you pass in just FormItems, you'll see that in fact controls of specific types are created, exactly as though you bound to the DataSource without specifying fields at all. So in this case the FormItems you pass are effectively just specifying which fields are present in each specific form (and can override whatever other properties you like).

                      This is covered in more detail in the QuickStart Guide chapter on DataBinding.

                      Comment


                        #12
                        How do i get the FormItems to DynamicForm.setItems()? If there's an example you can direct me to, that'd be great.

                        In the QuickStart Guide, I couldn't find anything on how to specify which FormItems of a ds.xml file are included in a DynamicForm. I'll read it over again but in the meantime, this is what I'm trying to do and it gives me the "destroyed item" warning...
                        Code:
                        DataSource ds = DataSource.get("myDs");
                        
                        DynamicForm form1 = new DynamicForm();
                        form1.setDataSource(ds);
                        form1.setFields(form1.getItem("item1"));
                        
                        // In another class ...
                        
                        DynamicForm form2 = new DynamicForm();
                        form2.setDataSource(ds);
                        form2.setFields(form2.getItem("item2"));
                        
                        // each form goes into their on tab and consolidated into a ValuesManager
                        My single data source contains...
                        Code:
                        ...
                        <field name="item1" type="integer" editorType="SpinnerItem"/>
                        <field name="item2" type="integer" editorType="TextItem"/>
                        ...
                        In the showcase, I've seen examples where new FormItems get constructed then added to a DynamicForm, but those examples set all the customizations in code instead of in a ds.xml file (e.g. http://www.smartclient.com/smartgwt/showcase/#layout_form_splitting).

                        Again, your help is much appreciated.

                        Comment

                        Working...
                        X