Rest Document Service

document, json, rest, xpages, xpages-extlib

Solution

The REST service should deliver a data array. This is what `xe:djxDataGrid` expects as it is a data grid control which shows data in multiple rows in a table.

The common way is to use the REST service `viewJsonService`. Define all columns you want to see in data grid in a view. You connect the view to REST service with parameter "viewName" and with `defaultColumns="true"` you make sure that all columns get delivered.

Your REST service definition would look like this then:

<xe:restService
    id="restService1"
    pathInfo="docAccReq1">
    <xe:this.service>
        <xe:viewJsonService
            viewName="AccessRequests"
            defaultColumns="true" />
    </xe:this.service>
</xe:restService>

The REST service delivers JSON data as an array:

[
  {
      "@entryid":"1-80EFAE936EA978A480257CE4002DBC67",
      "@unid":"80EFAE936EA978A480257CE4002DBC67",
      "@noteid":"12C7A",
      "@position":"1",
      "@read":true,
      "@siblings":200,
      "@form":"access",
      "Name":"Arun",
      "ACCESSREQUESTER":"Arun Agnihotri",
      "ACCESSREQUESTEDDATE":"2014-05-26T08:19:31Z"
  },
  {
      ...
  },
  ...
] 

The values "@position" and "@siblings" are important for Dojo Data Grid. They tell how many entries are in view and which position is the current data entry on. This allows to show a right sized vertical scroll bar at the right vertical position.

The Rest service `documentJsonService` you used delivers only one single JSON object (not an array) and doesn't provide those additional information.

Problem

I have following code where in I want to display data from a Rest Doc Service into Dojo Data Grid. Output of Rest service is fine but Datagrid siplay displays the column titles and nothing else. Here is my code: ``` <xp:panel> <xe:restService id="restService1" pathInfo="docAccReq1" rendered="true" state="true"> <xe:this.service> <xe:documentJsonService contentType="application/json" systemItems="63" var="docAcc" documentUnid="80EFAE936EA978A480257CE4002DBC67"> <xe:this.items> <xe:restDocumentItem itemName="Name" name="Name"> </xe:restDocumentItem> <xe:restDocumentItem itemName="ACCESSREQUESTER" name="ACCESSREQUESTER"> </xe:restDocumentItem> <xe:restDocumentItem itemName="ACCESSREQUESTEDDATE" name="ACCESSREQUESTEDDATE"> </xe:restDocumentItem> </xe:this.items> </xe:documentJsonService> </xe:this.service> </xe:restService> <xe:djxDataGrid id="djxDataGrid1" storeComponentId="restService1" store="docStore"> <xe:this.dojoAttributes> <xp:dojoAttribute name="autoWidth" value="true"></xp:dojoAttribute> </xe:this.dojoAttributes> <xe:djxDataGridColumn id="djxDataGridColumn1" field="Name"> </xe:djxDataGridColumn> <xe:djxDataGridColumn id="djxDataGridColumn2" field="ACCESSREQUESTER"> </xe:djxDataGridColumn> <xe:djxDataGridColumn id="djxDataGridColumn3" field="ACCESSREQUESTEDDATE"> </xe:djxDataGridColumn> </xe:djxDataGrid> <xe:firebugLite id="firebugLite1"></xe:firebugLite> </xp:panel> <xp:panel> <xc:ccDebugToolbar defaultCollapsed="true" collapseTo="left"></xc:ccDebugToolbar> </xp:panel> ```

Original source