Show TOC

Creating an OBN Dropdown MenuLocate this document in the navigation structure

Prerequisites

  • You add the following imports:

importjava.util.Iterator;
import com.sap.portal.obn.service.IOBNMetadata;
import com.sap.portal.obn.service.IOBNService;
import com.sap.portal.obn.service.OBNFactory;
importcom.sap.portal.obn.exceptions.OBNException;
importcom.sap.portal.obn.semanticlayer.operation.IOperation;
importcom.sap.portal.obn.service.IOBNImplementationMD;
importcom.sap.portal.obn.service.IOBNResolvingContainer;
importcom.sap.security.api.IPrincipal;

         

Context

You can create a dropdown menu in an iView that provides a set of links to related tasks, for example, related to a specific business object. For example, a user can get a set of links for all iViews for manipulating a specific business object, such as Details and Update iViews for the business object Customer .

For each task, the link can be different for users in different roles.

To implement a dropdown menu, an administrator would do the following:

  • Define a business object.

  • Define a set of operations (tasks) for the business object

  • Assign iViews to the operations.

A developer would do the following:

  • In the source iView, do the following:

    • For the current user, query OBN to check what iViews are available out of the iViews assigned to the operations of the business object.

    • Display a menu that includes a link for each operation for which the current user is assigned at least one iView.

      When the user selects a link for one of the operations, the iView with the highest priority is displayed.

Procedure


  1. Get a resolving container for your business object for the current user.

    String BO = "myBO";
    String systemAlias = "mySystemAlias";
    IPrincipal user = getUser(); 
        
    IOBNResolvingContainer obnResolvingContatiner = null;
     
    try {
        // Create OBNMetadata for business object, operation
        IOBNMetadata obnMetadata = OBNFactory.getInstance()
            .createOBNMetadata(BO, systemAlias, null, user);
             
        // Add parameters to be passed to implementing iViews
        obnMetadata.setParameter("param_1_name", OBNFactory.getInstance()
            .createOBNParameterData("param_1_value"));
        obnMetadata.setParameter("param_2_name", OBNFactory.getInstance()
            .createOBNParameterData("param_2_value"));
             
        // Get OBN service (valid for both technologies)
        IOBNService obnService = getOBNService();
       
        // Get a resolving container for the OBN metadata
        obnResolvingContatiner = obnService
            .getOBNResolvingContainer(user, obnMetadata);
    }
    catch (OBNException e) {
    // Handle exceptions
    }
    
                         
  2. Get all the default implementations for the business object's operations.

    The OBN function getAllDefaultImplementations() finds all the operations that have at least one implementation for the current user. For each operation, the function returns the implementation with the highest priority.

    Iterator dfltImplsIter = obnResolvingContainer
        .getAllDefaultImplementations().iterator();
                         
  3. For each implementation, get the OBN URL and the name of the operation.

    while (dfltImplsIter.hasNext()) {
        IOBNImplementationMD contextMenuImplementation = 
             (IOBNImplementationMD)dfltImplsIter.next();
     
        // Get OBN URL
        String ctxMenuImplementationOBNUrl = contextMenuImplementation
            .getOBNUrl(true);     
            
        // Get operation title (display name for menu item)
        IOperation operation = contextMenuImplementation
            .getOperationAttributesObject();
        String ctxMenuImplementationTitle = operation.getTitle();  
    
                         
  4. Create a menu that includes an option for each implementation OBN URL that was obtained in step 3.

    The exact code depends on the user interface technology. For more information about code for creating OBN links, see Creating an OBN Link (Portal Runtime) and Creating an OBN Link (Web Dynpro) .

            ... 
    // Code to create menu UI, using OBN URLs from the previous step
        }
    }
    catch(OBNException e) {
    // Handle exceptions
    }