Announcement

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

    foreignKey valueField displayField conundrum

    I have the following two datasources:

    Code:
    <DataSource    ID="buildReleaseDMI"    serverType="generic" 
    dropExtraFields="true">
        <fields>
            <field name="id"      type="sequence" hidden="true"       primaryKey="true"/>
            <field name="name"    type="text"     title="Name"        length="124"       required="true"/>
            <field name="urlLocation"    type="text"     title="URL"        length="1024"       required="true"/>
            <field name="enabled"    type="boolean"     title="Enabled"     required="false"/>
        </fields>
        <serverObject lookupStyle="new" className="com.db.am.dbinsight.web.dai.server.dmi.BuildReleaseDMI"/>
    </DataSource>
    Code:
    <DataSource    ID="projectDMI"    serverType="generic"
        dropExtraFields="true"    >
        <fields>
            <field name="id" type="sequence" hidden="true"  primaryKey="true"/>
            <field name="name" type="text" title="Name" length="255" required="true"/>
            <field name="buildRelease"    type="integer"     title="Release" 
            	required="true" constructor="ComboBoxItem" foreignKey="buildReleaseDMI.id">
            	<valueField>id</valueField>
            	<displayField>name</displayField>
            </field>
        <serverObject lookupStyle="new" className="com.db.am.dbinsight.web.dai.server.dmi.ProjectDMI"/>
    </DataSource>
    I have the classic window with 3 widgets on ListGrid, DetailViewer, and one DynamicForm.
    They are connected just the same as in the example provided by smartgwt (item, category).
    This code is working fine for a table that has no foreign keys.
    Now I am reusing the code and the ListGrid top portion shows fine all the fields except for the one that has a foreign key. In this case it shows the name of the current selected item instead of the name of the foreignKey both tables have the same column name.
    When I click in a row in this list the viewer and the form both show in the column with the foreign key the text "[object Object]" in the DynamicForm I get the drop down and the list is correctly fetch from the other datasource except for the selected item is as mention above.

    I am not sure what to do here. Here is my code for the ListGrid
    Code:
    public class ProjectGrid extends ListGrid {
    
        private final DataSource projectDS = DataSource.get("projectDMI");
    	public ProjectGrid(){
    
    		setDataSource(projectDS);
    		setUseAllDataSourceFields(true);
    		setAutoFetchData(true);
    
    		ListGridField itemName = new ListGridField("name","Name");
    		itemName.setShowHover(true); 
    		itemName.setWidth(50);
            ListGridField countryCodeField = new ListGridField("countryCode", "Region", 50);
            countryCodeField.setAlign(Alignment.CENTER);
            countryCodeField.setType(ListGridFieldType.IMAGE);
            countryCodeField.setImageURLPrefix("flags/16/");
            countryCodeField.setImageURLSuffix(".png");
            setFields(itemName,countryCodeField);
    		setCanEdit(false);
    		setCanDragRecordsOut(false);
    
    		setHeight(120);
    		setWidth100();
    		setSelectionType(SelectionStyle.SINGLE);
    		setRecordEnabledProperty(null);
    		
    	}
    }
    Thanks

    #2
    I am receiving this data so I am trying to display
    buildRelease.name
    I tought I would add a field and set it datapath to obtain "buildRelease.name"

    ListGridField buildRelease = new ListGridField("buildRelease.name","Build Release");
    buildRelease.setDataPath("buildRelease.name");

    but I am getting blank not sure what I am doing wrong. I also had to defined every field in the grid.

    {data:[
    {buildRelease:{enabled:true,id:10000,name:"5.12.05.714",urlLocation:"http://...",version:1}
    ,name:"LIC_MGR",trayPort:3333,countryCode:"DB",id:10000,
    jmxApplicationPort:4567,jmxServiceBean:"LicMgr",jmxServicePort:5555
    }]

    Comment


      #3
      so I did some more digging and now I see the data using
      buildRelease.setDataPath("buildRelease/name");

      Comment


        #4
        You don't typically want to use dataPath for this kind of ordinary id->display value mapping. Use dataSourceField.includeFrom instead, or if you cannot (custom Java server code), use field.valueXPath.

        Comment


          #5
          Now the last piece of the puzzle is to be able to save my changes. The problem I am having is that the editor panel is submitting the whole object as oppose to the Id I believe. The validation code of the DMI fails for this reason.

          Here is what the panel is sending:

          Code:
          === 2012-06-08 14:15:21,559 [l0-1] INFO  RequestContext - URL: '/showcase/sc/IDACall', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2': Moz (Gecko) with Accept-Encoding header
          === 2012-06-08 14:15:21,567 [l0-1] DEBUG XML - Parsed XML from (in memory stream): 7ms
          === 2012-06-08 14:15:21,571 [l0-1] DEBUG RPCManager - Processing 1 requests.
          === 2012-06-08 14:15:21,574 [l0-1] DEBUG RPCManager - Request #1 (DSRequest) payload: {
              criteria:{
                  id:10002
              },
              values:{
                  buildRelease:{
                      enabled:true,
                      id:10000,
                      name:"5.12.05.714",
                      urlLocation:"http://localhsot/Service/5.12.05.714.zip",
                      version:1
                  },
                  countryCode:"GM",
                  id:10002,
                  jmxApplicationPort:8020,
                  jmxServiceBean:"TestService",
                  jmxServicePort:25098,
                   name:"TEST_GM",
                  trayPort:25097,
                  _selection_6:true
              },
              operationConfig:{
                  dataSource:"projectDMI",
                  operationType:"update"
              },
              componentId:"isc_DynamicForm_0",
              appID:"builtinApplication",
              operation:"projectDMI_update",
              oldValues:{
                  buildRelease:{
                      enabled:true,
                      id:10000,
                      name:"5.12.05.714",
                      urlLocation:"http://localhsot/Service/5.12.05.714.zip",
                      version:1
                  },
                  countryCode:"GM",
                  id:10002,
                  jmxApplicationPort:8020,
                  jmxServiceBean:"TestService",
                  jmxServicePort:25098,
                  name:"TEST_GM",
                  trayPort:25097,
                  _selection_6:true
              }
          }
          === 2012-06-08 14:15:21,574 [l0-1] INFO  IDACall - Performing 1 operation(s)
          === 2012-06-08 14:15:21,838 [l0-1] DEBUG ValidationContext - Adding validation errors at path '/projectDMI/buildRelease': {errorMessage=Must be a whole number.}
          === 2012-06-08 14:15:21,839 [l0-1] INFO  Validation - Validation error: [
              {
                  buildRelease:{
                      errorMessage:"Must be a whole number."
                  }
              }
          ]
          Here is the code for the editor view:

          Code:
                  editorForm.setDataSource(projectDS);
                  editorForm.setUseAllDataSourceFields(true);
          
                  editorForm.setColWidths(50, 50, 50, 200);
              	
                  SelectItem buildRelease = new SelectItem("buildRelease", "Release");
          		buildRelease.setDataPath("buildRelease/id");         
                  SelectItem buildReleaseSelectItem = new SelectItem();
                  buildReleaseSelectItem.setOptionDataSource(buildReleaseDS);
                  buildRelease.setEditorType(buildReleaseSelectItem);
          
                  editorForm.setFields(buildRelease);

          Comment


            #6
            See above about dataPath vs includeFrom and valueXPath. Don't deliver the buildRelease sub-object to the client, just it's ID.

            Comment

            Working...
            X