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; 22nd 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; 22nd 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

              Working...
              X