Announcement

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

    PickTreeItem uses first foreignkey field for criteria instead of parentId

    Be sure your post includes:

    1. SmartClient Version: v8.3p_2013-05-22/LGPL Development Only (built 2013-05-22)

    2. Firefox 3.6.17

    3.

    4.

    5.

    6.
    Code:
    package pl.com.tech4.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.DOM;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.data.OperationBinding;
    import com.smartgwt.client.data.RestDataSource;
    import com.smartgwt.client.types.DSDataFormat;
    import com.smartgwt.client.types.DSOperationType;
    import com.smartgwt.client.types.DSProtocol;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.PickTreeItem;
    
    public class MainEntryPoint implements EntryPoint {
        
        public void onModuleLoad() {
    
            DOM.getElementById("loadingPicture").removeFromParent();
            layout();
            SC.showConsole();
        }
        
        private void layout() {
    
            RestDataSource ds = new RestDataSource();
            OperationBinding fetchBinding = new OperationBinding();
            fetchBinding.setOperationType(DSOperationType.FETCH);
            fetchBinding.setDataFormat(DSDataFormat.XML);
            fetchBinding.setDataProtocol(DSProtocol.POSTXML);
            ds.setOperationBindings(fetchBinding);
            
            DataSourceField fieldId = new DataSourceField();
            fieldId.setName("id");
            fieldId.setPrimaryKey(true);
            
            DataSourceField fieldTestId = new DataSourceField();
            fieldTestId.setName("testId");
            fieldTestId.setForeignKey("id");
            
            DataSourceField fieldParentId = new DataSourceField();
            fieldParentId.setName("parentId");
            fieldParentId.setForeignKey("id");
            
            ds.setFields(fieldId, fieldTestId, fieldParentId);
            
            PickTreeItem parentIdItem = new PickTreeItem("parentId");
            parentIdItem.setEmptyDisplayValue("A bug?");
            parentIdItem.setDataSource(ds);
            
            DynamicForm df = new DynamicForm();
            df.setFields(parentIdItem);
            df.setDataSource(ds);
            
            df.draw();
        }
        
    }
    When Datasource definition includes more than one foreign key field, then PickTreeItem creating Criteria request uses (I guess) the first foreign field listed in ds.
    Expanding PickTreeItem produces the following request:
    Code:
    <request>
        <data>
            <testId xsi:nil="true"/>
        </data>
        <dataSource>isc_RestDataSource_0</dataSource>
        <operationType>fetch</operationType>
        <oldValues></oldValues>
    </request>
    According to the docs for the Tree.setParentIdField(), the default field name for parent is "parentId". This is working fine in TreeGrid, but not in PickTreeItem as shown in above test case.
    Also, I can't find a way to explicit set parent field for PickTreeItem (for TreeGrid, setDataProperties() and Tree template can be used).
    MichalG

    #2
    Both TreeGrid and PickTreeItem will use the same method of auto-determining the tree fields (first foreignKey). The difference is, with TreeGrid you can override that choice via setDataProperties(), and there isn't currently a way to do so with PickTreeItem; the fields just need to be in the right order.

    So not a bug per se but you have pointed out that a setDataProperties() API would be useful on PickTreeItem; we'll note this down.

    Comment


      #3
      Both TreeGrid and PickTreeItem will use the same method of auto-determining the tree fields (first foreignKey)
      You are right - somehow missed this in my multiple tests.

      Well, according to the Tree.setParentIdField() docs:
      For trees with modelType "parent", this property specifies the name of the property that contains the unique parent ID of a node. Default value is "parentId".
      I assumed that if parentId field has this particular default name, then it can be anywhere around ds fields.
      Turns out that my assumption is wrong, but I would say docs are misleading here. Additionally, I have not found in documentation anything about "first foreignkey as parentId" method.

      Now, I am having trouble describing my team member who develops project, that class attributes should be in other order than the order which results from class inheritance.

      Can you point me to any workaround (other than changing fields order) when using PickTreeItem?
      Maybe the way to setDataProperties in PickTreeItem via JSNI?
      I need this form item type and I am stuck.
      Thanks,
      MichalG

      Comment


        #4
        Finally, I ended with something like this:
        Code:
        isc.ResultTree.addProperties({
            parentIdField: "parentId"
        });
        which workarounds my problem and also makes (just my opinion) ResultTree behavior consistent with docs.

        PickTreeItem.setDataProperies() would be a valuable extension, but this is beyond my javascript skills and SmartClient internals knowledge.
        Thanks,
        MichalG

        Comment


          #5
          The default setting for a Tree (no DataSource) is parentId. The default setting for a ResultTree is to use the first FK.

          Your change breaks the ability to detect any FK which is not named "parentId".

          If you are using autoDeriveSchema to derive fields from a bean, you can just re-declare selective fields to establish a different order. Be sure to look at the inheritsFrom discussion linked from autoDeriveSchema for details.

          Comment


            #6
            Your change breaks the ability to detect any FK which is not named "parentId".
            I understand but in situation with no ability to pick parentIdField via dataProperties (and any other way), I prefer hardcoded default name rather than count on fields order in ds definition.

            Also, please note that Menu widget does not have dataProperties exposed in SGWT API, neither.
            It has this attribute available in SmartClient, so it seems as a quick work to improve.
            Thanks,
            MichalG

            Comment


              #7
              Actually Menu has setDataProperties() because it's a subclass of ListGrid.

              Comment


                #8
                There is setDataProperties(ResultSet) inherited from ListGrid, but I meant Menu with databound tree data which is supposed to use ResultTree.
                And ResultTree has parentIdField attribute, which I need here.
                MichalG

                Comment


                  #9
                  That's a good point, we'll add a signature that takes ResultTree to Menu as well when we address this.

                  Comment


                    #10
                    dataProperties attribute added to PickTreeItem and Menu

                    We have just added dataProperties attribute to PickTreeItem and to Menu, so you can setup the Datastore properties as discussed.
                    For instance, now you can do this:

                    Code:
                    ...
                       PickTreeItem pickTreeItem = new PickTreeItem("PickTreeItem");
                       pickTreeItem.setEmptyDisplayValue("Select one value");
                    
                       RestDataSource ds = getDatasource();
                       pickTreeItem.setDataSource(ds);
                    	        
                       ResultTree config = new ResultTree();
                       config.setParentIdField("parentId");
                       pickTreeItem.setDataProperties(config);
                    
                       DynamicForm df = new DynamicForm();
                       df.setFields(pickTreeItem);
                    ...

                    Comment


                      #11
                      Just found it working as expected in PickTreeItem against 4.1d
                      SmartClient Version: SNAPSHOT_v9.1d_2013-06-17/LGPL Development Only (built 2013-06-17)
                      Thanks,
                      MichalG

                      Comment

                      Working...
                      X