Announcement

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

    DataSource Multiple Select Item

    Hi, I am new to SmartGWT, and trying to create an Interface to edit a <User> table that has a Field called <Groups>. The available groups are supplied with GroupsDS and the User Records through UserDS. Now, I need to Have the groups field of the User Record as multi Selectable, and its valueMap have to be populated with the Values of GroupsDS.
    and in the User record editing, the groups that the user has assigned, have to be selected in the multiSelect SelectItem(groups).

    How can I achieve this?

    Thank you

    #2
    What I have done so far is,
    created a SelectItem that is assigned to a editorForm(DynamicForm)
    and set the following
    Code:
            SelectItem groups = new SelectItem("groups", "Groups");
            groups.setMultiple(true);
            groups.setOptionDataSource(groupsDS);
            groups.setValueField("groupID");
            groups.setDisplayField("displayName");
    for the groupsDS
    Code:
            DataSource groupDS = new DataSource();
            groupDS.setDataFormat(DSDataFormat.JSON);
            groupDS.setDataURL("data/json/groups.js");
            DataSourceField groupID = new DataSourceField("groupID", FieldType.TEXT);
            DataSourceField groupDisplayName = new DataSourceField("displayName", FieldType.TEXT);
            groupID.setPrimaryKey(true);
            groupID.setRequired(true);
            groupDS.setFields(groupID,groupDisplayName);
    and the groups.js is
    Code:
    [
        {
            displayName:"People",
            groupID:"people",
            description:"more general group for people",
            notes:"These are people"
        },
        {
            displayName:"Server",
            groupID:"server",
            description:"Sever Computers",
            notes:"these are servers"
        }
    ]
    For editorForm
    Code:
            editorForm = new DynamicForm();
            editorForm.setDataSource(userDS);
            editorForm.setUseAllDataSourceFields(true);
            editorForm.setFields(groups);
    Where userDS is the UserDataSource, Defined as
    Code:
            RestDataSource userDS = new RestDataSource() {
                @Override
                protected Object transformRequest(DSRequest dsRequest) {
                    return super.transformRequest(dsRequest);
                }
                @Override
                protected void transformResponse(DSResponse response, DSRequest request, Object data) {
                	
                    super.transformResponse(response, request, data);
                    
                }
            };
    
            DataSourceField groups = new DataSourceField("groups", FieldType.ENUM, "Groups");
            userDS.setFields(groups); 
    
            userDS.setFetchDataURL("data/xml/responses/user_fetch_rest.xml");
    a sample UserData as follows
    Code:
    <response>
    <status>0</status>
    <startRow>0</startRow>
    <endRow>0</endRow>
    <totalRows>1</totalRows>
    <data>
    <record>
        <firstName>Banu</firstName>
        <userID>banu</userID>
        <groups>
           	<group>
           		<groupID>router</groupID>
          	</group>
           	<group>
           		<groupID>server</groupID>
          	</group>
        </groups>
    </record>
    Can anyone please tell me am I on the right Track,
    What xPath value I need to give for the groups to get them as an array of group.

    When I comple and run I didnt get any errors, But the groups Field is empty.

    Thank you
    Last edited by banuk77; 2 Aug 2010, 23:00.

    Comment


      #3
      The groups SelectItem have successfully populated from optionDataSource groupsDS,

      What I am trying to figure out now is reading the groups value as array of group from the UserDS, and that values have to be selected on the SelectItem.
      how this should be defined in response XML, and how to read that value as array of group.

      Thank you

      Comment


        #4
        Originally posted by banuk77
        The groups SelectItem have successfully populated from optionDataSource groupsDS,

        What I am trying to figure out now is reading the groups value as array of group from the UserDS, and that values have to be selected on the SelectItem.
        how this should be defined in response XML, and how to read that value as array of group.

        Thank you
        Banuk, I'm running in to the same issue. Did you get it to work?

        Comment

        Working...
        X