+

Search Tips   |   Advanced Search


Obtaining a model from the portal

Portal models can be obtained using three different ways, depending on where the code using them resides.

JNDI lookup

A JNDI lookup can be performed for code that resides in a request/response cycle of the portal, for example in a JSP. The lookup results in a home interface from which a model provider can be obtained. Interfaces for the models mentioned above can be found in com.ibm.portal.model.

To avoid calling the JNDI lookup too often, it is recommended to store the provider object. The following example, which is only applicable to non-portlet code running inside of a portal, shows how the content model is obtained using a JNDI lookup. Figure 1. Obtaining a content model using JNDI lookup

try{

Context ctx = new InitialContext();

ContentModelHome home = (ContentModelHome) ctx.lookup("portal:service/model/ContentModel"); if (home != null) { ContentModelProvider provider = home.getContentModelProvider(); ContentModel model = provider.getContentModel(aRequest, aResponse); ... }} catch (NamingException nx){ // some error handling code here}

Portlet service (standard portlet API)

Standard portlets can access models through specific portlet services.

These are located in com.ibm.portal.portlet.service.model.

The following example shows how the navigation model is obtained by a standard portlet.Figure 2. Obtaining the navigation model

PortletServiceHome psh; javax.naming.Context ctx = new javax.naming.InitialContext(); boolean serviceAvailable = false; try {
   psh = (PortletServiceHome) 
      ctx.lookup("portletservice/com.ibm.portal.portlet.service.model.NavigationModelProvider");
      serviceAvailable = true;} catch(javax.naming.NameNotFoundException ex) {
    ... error handling...}
... if (serviceAvailable) {

NavigationModelProvider provider = (NavigationModelProvider) psh.getPortletService(NavigationModelProvider.class);

NavigationModel model = provider.getNavigationModel(aRequest, aResponse); ...}

Portlet service (IBM Portlet API)

IBM portlets can access models through specific portlet services.

These are located in com.ibm.portal.ibmportlet.service.model.

The following example shows how the navigation model is obtained by an IBM portlet.Figure 3. Obtaining the navigation model (IBM portlet)

NavigationModelProvider provider = (NavigationModelProvider) 

PortletContext.getService("com.ibm.portal.ibmportlet.service.model.NavigationModelProvider"); if (provider != null) {

NavigationModel model = provider.getNavigationModel(aRequest, aResponse); ...}

Note the following limitations for obtaining a portal model:

  1. Portlets that use the following packages must not be enabled for parallel portlet rendering (PPR):

    • com.ibm.portal.admin.MarkupList

    • com.ibm.portal.admin.SkinList

    • com.ibm.portal.admin.ThemeList

    • com.ibm.portal.content.ContentMetaDataModel

    • com.ibm.portal.content.ContentModel

    • com.ibm.portal.navigation.NavigationModel

    • com.ibm.portal.navigation.NavigationSelectionModel

    • com.ibm.portal.portletmodel.PortletModel

    The restriction covers all the models that can be obtained from the above packages.

  2. WSRP portlets must not use the Model SPI.

  3. Model access is only possible after the portal has initialized the request appropriately. Access is possible inside of code invoked through the portal servlet. Models cannot be accessed in servlet filters.


Parent topic:

Model SPI overview


Related concepts


Sub packages of the Model SPI
Remote Model SPI REST service


Related reference


Model SPI samples


Related information


Obtaining the object ID for a page or portlet