Monday, June 8, 2009

Retrieving the rendering context within a WCM .jsp component



Question
How do you retrieve the rendering context within a Lotus Web Content Management (WCM) .jsp component?

Answer
Sample .jsp:
1. For the preview to work, place the code in the following directory:
\ibm\WebSphere1\profiles\wp_profile\installedApps\\wcm.ear\ilwwcm.war\jsp\html>

2. Access via a .jsp component configured with the following path: /jsp/html/render.jsp.
    Note that this .jsp will not work if accessed directly using a URL in a browser such as xxxx/wps/wcm/jsp/html/render.jsp. The .jsp must be accessed via Preview or a rendering portlet.

    If you are accessing the content via the Web Content Viewer local rendering portlet, you must also place the .jsp in the war/jsp/html directory for the local rendering portlet. Here is a sample location:

    \websphere\PortalServer\installedApps\WCM_Local_ng_Portlet_zkj5916.ear\zkj5916.war\jsp\html\
    If you use the Remote Rendering Portlet, you must place it there as well.
    <%@ taglib uri="/WEB-INF/tld/wcm.tld" prefix="wcm" %>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" %>
    <%@ page import="com.ibm.workplace.wcm.api.*" %>
    ">Cannot get Workspace

    <%

    RenderingContext currentRenderingContext = (RenderingContext) pageContext.getRequest().getAttribute(Workspace.WCM_RENDERINGCONTEXT_KEY);


    out.println("APP PATH: " +currentRenderingContext.getWcmWebAppPath() + "
    ");

    out.println("Servlet PATH: " +currentRenderingContext.getWcmServletPath() + "
    ");

    out.println("Rendering Context " +currentRenderingContext.getPath());

    %>

    <%--
    Note: if the rendering context is returning %2F instead of "/", you may want to use the string replaceAll method to modify. For example:

    String myContext = currentRenderingContext.getPath();
    String myModifiedContext = myContext.replaceAll("%2F", "/");
    --%>