Announcement

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

    How to render nested datasources in grid and form?

    Hi,

    I'm using the CompoundEditor (grid and form with common datasource) from the ShowCase and now stuck with the rendering when I use a nested datasource. Model is simple, I have userGroups, and all userGroup have a set of permissions.

    My datasources returning the following xml-s for fetch:

    userGroup:
    Code:
    <response>  
    	<status>0</status><startRow>0</startRow><endRow>2</endRow><totalRows>2</totalRows>
    	<data>
    		<record>
    			<id>1</id>
    			<name>user group 1</name>
    			<permissions>
    				<permission>1</permission>
    				<permission>2</permission>
    			</permissions>
    		</record>
    		<record>
    			<id>2</id>
    			<name>user group 2</name>
    			<permissions>
    				<permission>1</permission>
    				<permission>2</permission>
    			</permissions>
    		</record>
    	</data> 
    </response>
    permissions:
    Code:
    <response>  
    	<status>0</status><startRow>0</startRow><endRow>2</endRow><totalRows>2</totalRows>
    	<data>
    		<record>
    			<id>1</id>
    			<name>permission 1</name>
    		</record>
    		<record>
    			<id>2</id>
    			<name>permission 2</name>
    		</record>
    	</data> 
    </response>
    I'm setting the permissionsField's type to the permissions datasource ID, also setting the foreign key and children properties. (cannot set here the editorTYpe until Sanjiv do not fix it, see http://forums.smartclient.com/showthread.php?p=19128)
    Code:
    DataSourceField permissionsField = new DataSourceIntegerField( "permissions", "Permission IDs" );
    permissionsField.setForeignKey( DS_USER_GROUPS + ".id" );
    permissionsField.setChildrenProperty( true );
    permissionsField.setType( DataSource.get( DS_PERMISSIONS ) );
    The problem is, that both the grid and the form is displaying only [object Object]. Since I cannot set the editorType on DataSourceField, I tried to add a ListGridField and a SelectItem to the grid and form, but it does not help. Also tried to use the optionDataSource property on the SelectItem, but still not working.
    Can anybody mention a workaround or do I miss anything? I have a worry, that it was left out from ShowCase for reason...

    #2
    What type of display are you looking for?

    You can set the setMultiple(true) on the permissions field - that's going to give you a display like "1,2".

    Comment


      #3
      I tried that

      Thanks for the answer. Yes rendering is ok then, but unfortunately it produces wrong request to the server. (EDIT no2: I misunderstood the docs)

      The requests for update when setMultiple(true) is not called on the permissions field (values are the same, since SelectItem shows only one row with [object Object]):

      Code:
      <request>
          <data>
              <userGroups>
                  <id>1</id>
                  <name>user group 1</name>
                  <permissions>
                      <permission>1</permission>
                      <permission>2</permission>
                  </permissions>
              </userGroups>
          </data>
          <oldValues>
              <id>1</id>
              <name>user group 1</name>
              <permissions>
                  <permission>1</permission>
                  <permission>2</permission>
              </permissions>
          </oldValues>
          <dataSource>userGroups</dataSource>
          <operationType>update</operationType>
          <operationId></operationId>
          <startRow></startRow>
          <endRow></endRow>
          <sortBy></sortBy>
          <textMatchStyle></textMatchStyle>
          <componentId>isc_OID_31</componentId>
      </request>
      and when it is called:

      Code:
      <request>
          <data>
              <userGroups>
                  <id>1</id>
                  <name>user group 1</name>
                  <permissions><permissions>1</permissions><permissions>2</permissions>
                  </permissions>
              </userGroups>
          </data>
          <oldValues>
              <id>1</id>
              <name>user group 1</name>
              <permissions><permissions>1</permissions><permissions>2</permissions>
              </permissions>
          </oldValues>
          <dataSource>userGroups</dataSource>
          <operationType>update</operationType>
          <operationId></operationId>
          <startRow></startRow>
          <endRow></endRow>
          <sortBy></sortBy>
          <textMatchStyle></textMatchStyle>
          <componentId>isc_OID_72</componentId>
      </request>
      Any other idea? Can it be SmartGWT specific?

      * Also I'll be happy if I can make it render the name of the permissions instead of IDs, but, the orig issue is more important.
      *2 ok, I've found that javaDoc says: "there will be a "wrapper element" named after the field name". It will be so nice if we can define this wrapper tag... But now the question is simply how to render the permission names instead of 1,2? Is it possible without using DataSourceField.setEditorType() ?
      Last edited by jamesgt; 21 Mar 2009, 07:24.

      Comment


        #4
        Just a note: it looks like ListGridField.setCellFormatter() also fails with field that contains multiple value.

        18:49:07.650:RDQ7:WARN:Log:Unrecognized type object for value 1,2

        Comment


          #5
          The next build will allow you to specify childTagName to "permission".

          Comment


            #6
            Added DataSourceField.setChildTagName(..) to SVN.

            Comment

            Working...
            X