Determining the current web content context
To determine the current web content context of a portal page or Web Content Viewer portlet, use the Web Content Manager (WCM) Page Context Service. This service provides the ID of the item currently rendered on a page or portlet.
The WCMPageContextService provides the following two methods:
-
Use
getWcmPageContextto return the ID of the current web content context. Depending on the parameters passed, the method returns the context of a page or a Web Content Viewer portlet.The service evaluates conditions in the following order until it finds a valid context, stopping evaluation after finding a match:
- Private render parameter (available only for Web Content Viewer portlets)
path-infoparameter- Public render parameter
- Portlet configuration setting for the Web Content Viewer (Web Content Viewer portlets only)
- Web content association defined for the page
The context can be a content item or site area.
-
Use
getWcmDefaultContentto return the default content of a site area. This method is useful if the current web content context is a site area and you must determine which content item is rendered.
Both methods return the document ID of the current context or default content. If necessary, us getPathById in the WCM workspace to convert the ID to the corresponding content path. For more information, refer to getPathById.
Obtaining an instance of the service
To obtain an instance of the service, use one of the following home interfaces:
- Use
PortalWcmPageContextServiceHomeif the calling code has access toHttpServletRequest(for example, if a theme calls the service). - Use
PortletWcmPageContextServiceProviderif the calling code has access toPortletRequest(for example, if a portlet calls the service). - Use
CorWcmPageContextServiceHomeif the calling code has access tocom.ibm.content.operations.registry.api.Context(for example, if a resolver calls the service).