Announcement

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

    Datasource with foreign key works for DynamicForm,but not for ListGrid or DetailsView

    version: v8.3p_2012-12-28/Pro Deployment (built 2012-12-28)

    I use Hibernate-Beans and autoDerived Datasources. There are two classes with an One-To-Many relationship.

    I use "foreignKey" to create the relationship, "displayField" to set the displayed field and editorType="SelectItem" to let the user choose between the instances of the referenced class (or rows of the corresponding table).

    This works fine, when I use the datasource for a DynamicForm. The user can select the referenced instance, submit and the database is updated fine.
    But it doesn't work for a ListGrid. The Column is blank and the DropDownList of the filter shows two empty cells.
    Neither does it work for a details viewer, the field is empty.

    So, how can I make it work with ListGrid and DetailsViewer too?

    Datasources
    Code:
    <DataSource
    	ID="rolle"
    	serverType="hibernate"
    	schemaBean="de.bml.web.versandanzeige.server.model.Rolle"
    	autoDeriveSchema="true">
    	<fields>
    		<field
    			name="aktiv"
    			hidden="true" />
    		<field
    			name="bezeichnung" />
    	</fields>
    </DataSource>
    Code:
    <DataSource
    	ID="nutzerlogin"
    	serverType="hibernate"
    	schemaBean="de.bml.web.versandanzeige.server.model.NutzerLogin"
    	autoDeriveSchema="true">
    	<fields>
    		<field
    			name="aktiv"
    			hidden="true" />
    		<field
    			name="passwortHash"
    			hidden="true" />
    		<field
    			name="kennung" />
    		<field
    			name="nachname" />
    		<field
    			name="vorname" />
    		<field
    			name="rolle" foreignKey="rolle.id" displayField="bezeichnung" editorType="SelectItem" />
    		<field
    			name="idExtern" />
    	</fields>
    </DataSource>
    Attached Files

    #2
    See DataSourceField.includeFrom.

    Comment


      #3
      Code:
      <DataSource
      	ID="nutzerlogin"
      	serverType="hibernate"
      	schemaBean="de.bml.web.versandanzeige.server.model.NutzerLogin"
      	autoDeriveSchema="true">
      	<fields>
      		<field
      			name="aktiv"
      			hidden="true" />
      		<field
      			name="passwortHash"
      			hidden="true" />
      		<field
      			name="kennung" />
      		<field
      			name="nachname" />
      		<field
      			name="vorname" />
      		<field
      			name="rolle" foreignKey="rolle.id" displayField="bezeichnung" includeFrom="rolle.bezeichnung" editorType="SelectItem" />
      		<field
      			name="idExtern" />
      	</fields>
      </DataSource>
      same result

      Code:
      <DataSource
      	ID="nutzerlogin"
      	serverType="hibernate"
      	schemaBean="de.bml.web.versandanzeige.server.model.NutzerLogin"
      	autoDeriveSchema="true">
      	<fields>
      		<field
      			name="aktiv"
      			hidden="true" />
      		<field
      			name="passwortHash"
      			hidden="true" />
      		<field
      			name="kennung" />
      		<field
      			name="nachname" />
      		<field
      			name="vorname" />
      		<field
      			name="rolle" foreignKey="rolle.id" includeFrom="rolle.bezeichnung" editorType="SelectItem" />
      		<field
      			name="idExtern" />
      	</fields>
      </DataSource>
      Not working either. Looks like it has no effect at all.

      Btw, I'm using PRO, and "includeFrom" is not in the JavaDocs (it's referenced, but not documented). Is this intentional?

      Comment


        #4
        works now

        Found the answer in this thread: http://forums.smartclient.com/showthread.php?t=23289&highlight=includeFrom

        Code:
        <DataSource
        	ID="nutzerlogin"
        	serverType="hibernate"
        	schemaBean="de.bml.web.versandanzeige.server.model.NutzerLogin"
        	autoDeriveSchema="true">
        	<fields>
        		<field
        			name="aktiv"
        			hidden="true" />
        		<field
        			name="passwortHash"
        			hidden="true" />
        		<field
        			name="kennung" />
        		<field
        			name="nachname" />
        		<field
        			name="vorname" />
        		
        		<field
        			includeFrom="rolle.bezeichnung" hidden="true" />
        		<field
        			name="rolle" foreignKey="rolle.id" displayField="bezeichnung" editorType="SelectItem" />
        		<field
        			name="idExtern" />
        	</fields>
        </DataSource>

        Comment


          #5
          see post below
          Last edited by david.moers; 22 May 2019, 03:10.

          Comment


            #6
            I have the same problem while using ClientOnly-Datasources with cached data. For example I define a DataSourceField like this:
            Code:
            DataSourceField field = new DataSourceField();
            field.setForeignKey("Locations.id");
            field.setForeignDisplayField("description");
            In my ListGrid is just displayed the id like "BP01000..."
            Click image for larger version  Name:	Unbenannt.PNG Views:	2 Size:	1.8 KB ID:	257867

            When I edit the record row in my ListGrid, there's the correct description like "144.N":
            Click image for larger version  Name:	Unbenannt.PNG Views:	2 Size:	1.7 KB ID:	257868

            and also in an edit form it is correct:
            Click image for larger version  Name:	Unbenannt.PNG Views:	2 Size:	2.0 KB ID:	257869

            I found and read a lot about includeFrom etc. and tried to set it via attribute to another DataSourceField with two fields and so on, but that's not working.
            Also I tried to setOptionsDataSource and setAutoFetchDisplayMap(true) to the ListGridField, but no...

            Is the ForeignKeyDisplayField (and includeFrom) only working on database based DataSources or can I also use it on ClientOnly-Datasources and set it programmatically?
            Last edited by david.moers; 22 May 2019, 03:08.

            Comment


              #7
              Please revisit the docs for dataSourceField.includeFrom. We explain how to set up a displayField for this use case.

              includeFrom is limited to server-side DataSources, as it’s a join, and there’s no efficient way to do that with eg two REST services. If you are not using our server DataSources, then you need to return the same data that would be returned by includeFrom.

              Comment


                #8
                Dear all,

                So, for client-only DataSources, can I use foreign key for ManyToOne relation between two DataSources??

                I want to display the roleDataSource.role in the column of userDataSource.role.

                I tried as below but it does not work. Is there any way to solve this?

                Sets of data:
                Code:
                roleData = [
                    {
                        "id": 1,
                        "role": "ADMIN"
                    },
                    {
                        "id": 2,
                        "role": "USER"
                    }
                ];
                
                userData= [
                    {
                        "id": 1,
                        "username": "Bill",
                        "role": "1"
                    },
                    {
                        "id": 2,
                        "username": "lssss",
                        "role": "2"
                    };
                ]
                DataSource created correspondingly:
                Code:
                isc.DataSource.create({
                    ID: "roleDataSource",
                    fields:[
                        {name:"id", title:"ID", primaryKey: true},
                        {name:"role", title:"Role", required:true}
                    ],
                    clientOnly: true,
                    testData: roleData
                })
                
                isc.DataSource.create({
                    ID: "userDataSource",
                    fields:[
                        {name:"id", title:"ID", width: 40, primaryKey:true},
                        {name:"username", title:"Username"},
                        {name:"role", title:"Role", foreignKey:"roleDataSource.id",  displayField: "roleDataSource.role"}
                    ],    
                    clientOnly: true,
                    testData: userData
                })
                To display in a listGrid:
                Code:
                isc.ListGrid.create({
                    ID: "userAndRoleList",
                    width:500, height:224, alternateRecordStyles:true, showAllRecords:true,
                    dataSource: userDataSource,
                    autoFetchData: true
                })
                Thanks a lot!

                Leo

                Comment


                  #9
                  Hi Leochan,

                  try it like this here:

                  Code:
                  roleData = [
                      {
                          "id": 1,
                          "role": "ADMIN"
                      },
                      {
                          "id": 2,
                          "role": "USER"
                      }
                  ];
                  
                  userData = [
                      {
                          "id": 1,
                          "username": "Bill",
                          "role": "1"
                      },
                      {
                          "id": 2,
                          "username": "lssss",
                          "role": "2"
                      }
                  ];
                  
                  isc.DataSource.create({
                      ID: "roleDataSource",
                      fields:[
                          {name:"id", title:"ID", primaryKey: true},
                          {name:"role", title:"Role", required:true}
                      ],
                      clientOnly: true,
                      testData: roleData
                  });
                  
                  isc.DataSource.create({
                      ID: "userDataSource",
                      fields:[
                          {name:"id", title:"ID", width: 40, primaryKey:true},
                          {name:"username", title:"Username"},
                          {name:"role", title:"Rolename", foreignKey:"roleDataSource.id",  [B]displayField: "roleName"[/B]},
                  [B]{name:"roleName", foreignKey:"roleDataSource.id", includeFrom:"roleDataSource.role"}[/B]
                      ],    
                      clientOnly: true,
                      testData: userData
                  });
                  
                  isc.ListGrid.create({
                      ID: "userAndRoleList",
                      width:500, height:224, alternateRecordStyles:true, showAllRecords:true,
                      dataSource: userDataSource,
                      autoFetchData: true
                  });
                  Note that this works only in 13.0d, and not 12.0p/12.1p, see this blog post.

                  Best regards
                  Blama

                  Comment


                    #10
                    This works perfectly!! Thanks Blama

                    Comment

                    Working...
                    X