Announcement

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

    ListGrid SelectItem Showing Incorrect Values on ForeignKey Relationship

    SmartClient Version: v10.1p_2016-12-11/Enterprise Deployment (built 2016-12-11)
    Chrome Version 64.0.3282.167


    I have two objects, Contract and Pipeline. Each Contract has an attribute containing an integer key that references a Pipeline.

    I have a ListGrid that displays rows of Contract data with a datasource xml defining the fields, and a separate Pipeline datasource xml because I have another grid elsewhere that shows Pipeline information. Both datasource xml files have operation bindings to Java files that interact with an Oracle SQL database. One of the columns of my Contract ListGrid shows the Pipeline key reference, but I want it to show the String name for the referenced Pipeline. After searching the forums and docs, I setup a foreignKey relationship on my Contract datasource field like so:

    contract.ds.xml
    Code:
    <DataSource ID="contract" allowAdvancedCriteria="true">
        <fields>
            <field name="contractKey" title="Key" hidden="true" type="integer" primaryKey="true" required="true"/>
    
            <field name="name" title="Name (Full)" hidden="false" type="text" canEdit="true" width="10%"/>
            <field name="abbrev" title="Abbrev" hidden="false" type="text" canEdit="true" width="6%"/>
            <field name="contractRef" title="Contract Ref" hidden="false" type="text" canEdit="true" width="10%" cellAlign="center"/>
            <field name="description" title="Description" hidden="false" type="text" canEdit="true" width="10%"/>
            <field name="pipelineKey" title="Pipeline" hidden="false" type="integer" canEdit="true" width="10%" cellAlign="center" foreignKey="pipeline.pipelineKey" displayField="pipeline.name" valueField="pipelineKey"/>
        </fields>
        <operationBindings>
            <binding operationType="fetch" serverMethod="executeFetch">
                <serverObject className="com.my.app.contracts.ContractDS"/>
            </binding>
        </operationBindings>
    </DataSource>
    pipeline.ds.xml
    Code:
    <DataSource ID="pipeline" allowAdvancedCriteria="true">
        <fields>
            <field name="pipelineKey" hidden="true" title="Key" type="integer" primaryKey="true"/>
    
            <field name="name" hidden="false" title="Pipeline Name" type="text" width="20%" canEdit="true" required="true"/>
            <field name="description" hidden="false" title="Description" type="text" width="30%" canEdit="true"/>
            <field name="pipelineType" hidden="false" title="Type" type="text" width="10%" canEdit="true" required="true"/>
        </fields>
        <operationBindings>
            <binding operationType="fetch" serverMethod="executeFetch">
                <serverObject className="com.my.app.pipeline.PipelineDS" />
            </binding>
        </operationBindings>
    </DataSource>
    ContractGrid.java with some code and information redacted for privacy
    Code:
    public class ContractGrid extends ListGrid
    {
    public ContractGrid()
        {
            super(DataSource.get("contract"));
            this.setCanEdit(true);
            this.setDataFetchMode(FetchMode.LOCAL);
            this.setCriteria(place.getDateCriteria());
            this.setWidth(100);
    ​​​​​​​        this.setHeight(100);
            this.setDrawAheadRatio(4);
            this.setCanExpandRecords(true);
            this.setAutoFetchData(true);
        }
    }
    Currently, when my Contract grid is populated with Contract data rows, the "Pipeline" column still shows the integer pipelineKey value, but if I double click on that field to edit it I get a SelectItem filled with Pipeline names (which is partially what I want). If I set the field to a different Pipeline, the Pipeline name will stay displayed in the field while that row indicates it has edits. Saving or refreshing the data causes the pipelineKey to be shown again. What I'd like is for the Pipeline names to be shown at all times, but the pipelineKey to be the value that is actually stored on the Contract object. Can anyone help me figure out what I need to do to always show the pipeline names, both when editing and when just displaying data?

    #2
    Hi Pro-crastinator ,

    you are missing your displayField (which you define as displayField="pipeline.name", "." not allowed).
    Code:
    <field name="pipelineKey" ... displayField="pipeline_name" />
    <field name="pipeline_name" includeFrom="pipeline.name" />
    See these posts for similar questions. Also make sure to read the Quick Start Guide PDF front to back.

    Best regards
    Blama

    Comment


      #3
      Originally posted by Blama View Post
      Hi Pro-crastinator ,

      you are missing your displayField (which you define as displayField="pipeline.name", "." not allowed).
      Code:
      &lt;field name="pipelineKey" ... displayField="pipeline_name" /&gt;
      &lt;field name="pipeline_name" includeFrom="pipeline.name" /&gt;
      See these posts for similar questions. Also make sure to read the Quick Start Guide PDF front to back.

      Best regards
      Blama
      Hi Blama ,

      Thanks for your reply. I should have mentioned that I had tried that approach already, based on what I saw in the DataSourceField docs for includeFrom, but that approach presents a different issue: I can set breakpoints in my IDE and see that data is being returned from the server, but on the client side the grid displays no Contract object data and the developer console shows that the RPC Response comes back with no data.

      I guess at this point, my question is: why is it that the correct display values (pipeline.name) only gets displayed when I'm editing the field and not all the time? That tells me that the field is getting the correct data from the pipeline datasource, it's just not always displaying the information correctly.

      Comment


        #4
        Please revisit the docs for dataSourceField.includeFrom: it causes dispalyField values to be included with every record, so that you can see it for instance in every grid row, and not just the currently edited grid row (where a fetch can potentially be done just for the current record).

        It sounds as though you tried to use the includeFrom attribute, but something went wrong. Revisit that attempt, and this time look at the server-side logs to find out what's happening (this is always the first troubleshooting step for a server-side issue).

        Comment


          #5
          Hi Pro-crastinator.

          "RPC Response comes back with no data" could mean that the join results in 0 rows, because the pipelineKey is empty. In that case, use joinType="outer" on the field with the foreignKey.
          Check the generated SQL in the server side log if it looks like you expect it to look.
          Asides of this, this is working for me.

          Best regards
          Blama

          Comment

          Working...
          X