Announcement

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

    SelectItem (picklist mode): Problem mapping checked values

    Hi all,

    I'm using the SelectItem component configured this way:
    Code:
    private SelectItem pvrs = new SelectItem("pvrs", "PVR");
    this.pvrs.setMultiple(true);
    this.pvrs.setMultipleAppearance(MultipleAppearance.PICKLIST);
    this.pvrs.setDataPath("editorialData/pvrSet");
    this.pvrs.setGlobalTabIndex(13);
    I'm not filling options with a datasource but I managed to fill options this way:
    Code:
    this.pvrs.setValueMap((LinkedHashMap<Long, String>) formOptions.get("PVR"));
    The options values comes from this JSON:
    Code:
    "formOptions" : {
        "PVR" : {
            "48" : "None",
            "51" : "Lan",
            "49" : "Priv",
            "50" : "Pub",
            "52" : "Usb",
            "53" : "NPVR"
        },
    ...
    }
    This select item is attached to a DynamicForm which use a datasource that sends the following json:
    Code:
     {  
       "response":{  
          "status":0,
          "data":
             {  
                "id":1,
                "editorialData":{
                   "pvrSet":[  
                      {  
                         "id":48,
                         "displayedValue":"None"
                      },
                      {  
                         "id":50,
                         "displayedValue":"Pub"
                      },
                      {  
                         "id":52,
                         "displayedValue":"Usb"
                      }
                   ]
                }
             }
       }
    }
    As you can see, my select item is configured to map:
    Code:
    this.pvrs.setDataPath("editorialData/pvrSet");
    How can I map (check or uncheck) what I receive from the server to what is previously filled as options?

    I'm using the following versions:
    Isomorphic SmartClient/SmartGWT Framework (v10.0p_2015-11-20/Pro Deployment 2015-11-20)
    GWT 2.7
    Firefox 38

    #2
    We don't recommend using dataPath unless you are in a legacy use case where you are passing compound documents back and forth with your server, making it impossible to use DataSources normally (that is, access each entity type separately).

    It looks like instead you would to use valueXPath, and possibly some additional code in DataSource.transformResponse. Your goal is to provide "pvrs" as an Array of Integers, as that's what a multiple:true SelectItem expects (and produces, when the user checks or unchecks values).

    Comment


      #3
      Hi,
      Thanks for this answer but I must admit that I don't really understand how to use valueXPath in our case. Indeed, there is no such field on FormItems but only on DataSourceFields.

      In our view, we only set a DataSource on the parent DynamicForm, which is mainly used to give the DataUrl corresponding to this entity :

      Code:
      <DataSource ID="commercialchannel"
          dataURL="/THE/DATA/URL">
          <fields>
              <field primaryKey="true" name="id" hidden="true" type="sequence" />
              <field name="a" title="A" type="text" required="true"/>
              <field name="b" type="referencedata" />
              <field name="c" title="C" type="recommendation" />
              <field name="d" title="D" type="recommendation" />
              <field name="editorialData" type="editorialData"/>
         </fields>
      </DataSource>
      How should we use valueXPath in this case, to indicate that the SelectItem must get data from "editorialData/pvrSet" ?
      Should we add a field named pvrSet like that :

      Code:
      <field name="pvrSet"  valueXPath="editorialData/pvrSet"/>
      ?

      Moreover, isn't there a different way to modify the response than transformResponse because the DataSource creation is common to all the objects of our application ?

      Comment


        #4
        So to reiterate:

        Your goal is to provide "pvrs" as an Array of Integers, as that's what a multiple:true SelectItem expects (and produces, when the user checks or unchecks values).
        By the time the data has been processed by the DataSource, and before the data reaches any components, you want it to be represented as we describe above ("pvrs" as an Array of Integers). Otherwise, you are creating the problem that every component needs to be adapted to this custom in-memory data structure, instead of doing this once at the DataSource level, when the data is received.

        valueXPath and dataSource.transformResponse are the APIs you would use at the DataSource level to transform the data received from your server to the data format used by all of SmartGWT's UI components.

        Comment

        Working...
        X