Show TOC

Procedure documentationImplementing an Extended Toolbox Application Using JSON List API Locate this document in the navigation structure

 

To implement an extended toolbox application, you need to implement a portal component that provides the data to display in the extended toolbox. To do this, you use the JSON List API. The JSON List API, which is contained in the com.sap.portal.navigation.json.list package, enables you to create and consume portal components that expose lists of data that are represented as JSON objects. A JSON List component returns an ordered list of items and folders that contain items. The order of the list is defined by the insertion order (first in, first out).

The following example demonstrates how to use the JSON List API to implement an extended toolbox application that displays a list of documents.

The example shows how a single application can handle two scenarios, according to the content type of the request (MIME type). If the content type is application/json, then the getJSONList method is called; otherwise, the doContent method of the portal component is called. An example of such usage exists in the toolbox: if the value of the application's Mobile Perspective property is set to Toolbox Extended, a request for a JSON object attribute is made, whereas if the value is set to Toolbox, a standard call is made to the doContent method of the portal component.

Procedure

  1. In SAP NetWeaver Developer Studio, open the Enterprise Portal perspective and create a portal application project.

    For more information, see Creating a Portal Application Project.

  2. In the portalapp.xml file, set a sharing reference to com.sap.portal.navigation.json.helper.api.

  3. In the portal application project, create a portal component.

  4. Change the component inheritor class from AbstractPortalComponent to AbstractJSONListComponent.

  5. Add the following imports:

    Example Example

    1. import com.sap.portal.navigation.json.list.AbstractJSONListComponent;
    2. import com.sap.portal.navigation.json.list.JSONList;
    End of the code.
  6. Implement the AbstractJSONListComponent interface by implementing the getJSONList method. For example:

    Example Example

    1. //Create a new JSONList
    2. JSONList documentsJSONList = new JSONList();
    3. //Get a list of all the documents from a documents service
    4. List<Document> allDocuments = MyDocumentsService.getAllDocuments(request);
    5. //For all the documents in the list
    6. for (Document document : allDocuments){
    7.     //For each document or document folder - create a new JSONListItem
    8.     JSONListItem item = new JSONListItem(document.getID(), document.getTitle());
    9.     //If the item is a folder, set its type to FOLDER, as the default type is ITEM
    10.     if(JSONListConstants.JSONListItemType.FOLDER == document.getType()){
    11.         item.setType(JSONListConstants.JSONListItemType.FOLDER );
    12.     }
    13.     //Add the item to the JSONList
    14.     documentsJSONList.addItem(item);
    15. }
    16. //Return the JSONList
    17. return documentsJSONList;
    End of the code.
  7. To use the application as a regular portal component, you can also add an implementation in the doContent method of the portal component. For example:

    Example Example

    1. //Include HTML, CSS and JavaScript files
    2. IResource html = request.getResource(IResource.STATIC_PAGE, "html/documents.html");
    3. IResource css = request.getResource(IResource.CSS, "css/documents.css");         
    4. IResource js = request.getResource(IResource.SCRIPT, "scripts/documents.js");   
    5. response.include(request, html);
    6. response.include(request, css);
    7. response.include(request, js);
    End of the code.
  8. Build and deploy your application. For more information, see Deploying a Portal Application.

  9. Add the application to your mobile role.

  10. Set the value of the application‘s Mobile Perspective property to Toolbox Extended.

  11. Refresh your mobile portal and check that your application is visible in the extended toolbox.