+

Search Tips   |   Advanced Search

Web Content Manager JSP tags

We use JSP tags to pull WCM content and components.

A JSP referenced within a JSP component must not include a reference, directly or indirectly, to the same JSP component. This includes references within WCM tags or the API. If it does, a loop is created and the server will crash.

To use the WCM JSP tags, use directive:

    <%@ taglib uri="/WEB-INF/tld/wcm.tld" prefix="wcm" %>

JSP files are stored within a web application that runs on the portal. To reference a JSP file in another web application...

    contextPath;jspPath

For example:

    /wps/customapplication;/jsp/jspFilename.jsp

A dynamic context path value can be defined by adding a token to the context path that corresponds to a key and value pair to the WCM configuration service environment provider. When this key is used as the token in the jsp value field, it is replaced dynamically at render time. For example:

    my.custom.key;myfile

...where my.custom.key is a constant within the WCM configuration service.

Writing JSP to be referenced within a JSP component:

The setExplicitContext and setContext tags are not required when displaying a JSP file with a JSP Component. They are only required when directly accessing a JSP file.

Reloading JSP files:

JSP files referenced by Web Content Manager are reloaded once every 10 seconds. If we update a JSP file, we may need to wait for it to be reloaded before the changes will be displayed.


InitWorkspace tag

Set the initial workspace. This tag:

  • sets the WCM Workspace as a local variable called wcmWorkspace.

  • sets the WCM Workspace on the pageContext as a parameter with key com.ibm.workplace.wcm.api.Workspace.WCM_WORKSPACE_KEY.

  • sets the WCM RenderingContext on the request as a parameter with key Workspace.WCM_RENDERINGCONTEXT_KEY

    <wcm:initworkspace username=" " password=" " user=" " >
        [Error Message]
    </wcm:initworkspace>
    

Parameter Details
username The user name of a valid WCM user.
user Specify a Java.security.Principal object instead of the username.
password The password for the valid WCM username or user.

Username, user, and password are optional. If not specified, the current user will be used instead, including the anonymous user.

    <%@ taglib uri="/WEB-INF/tld/wcm.tld" prefix="wcm"%>
    <%@ page import="com.ibm.workplace.wcm.api.*" %>
    
    <p><wcm:initworkspace>login fail</wcm:initworkspace>
    <%
    
    // Get the workspace for use   
    Workspace workspace = (Workspace) pageContext.getAttribute(Workspace.WCM_WORKSPACE_KEY);
    
    // Get the WCM rendering context for use   
    RenderingContext renderingContext = (RenderingContext) request.getAttribute(Workspace.WCM_RENDERINGCONTEXT_KEY);
    %>
    


Explicit context tag

Set the path to the WCM server. not required in JSP displayed via a JSP component.

    <wcm:setExplicitContext wcmWebAppPath=" " 
              wcmServletPath=" " 
              path=" "
              requestParameters" " 
              prefix=" " 
              project=" " >
    
        [Error Message]
    
    </wcm:setExplicitContext>

    Parameter Details
    wcmWebAppPath The URL up to the web application. For example: http://localhost:10040/wps/wcm
    wcmServletPath The servlet path to the WCM servlet. For example: /connect
    path The path to the content and site areas. For example: /Site Area A/ Site Area B/Content C
    requestParameters We specify java Map request parameters to set in the context. These parameters can be used by menu components rendered via the JSP that use a query string.
    project The name of the project to set in the context. If the corresponding project cannot be found, it will be ignored and an error will be logged. An empty string is used to clear any project previously set in the context.

    The project, wcmWebAppPath and wcmServletPath parameters are optional. However, if wcmWebAppPath is specified, wcmServletPath must also be specified.

    Developers can add insert context tags at any place in the page and it will change the context for the rest of the page execution, but the tags cannot be nested.


    Context retrieval tag

    Sets the context given the location of a path string. This is not required in JSP displayed via a JSP component.

    <wcm:setContext location=" "  
      wcmWebAppPath=" " 
      wcmServletPath=" " 
      param=" " 
      project=" " 
      defaultPath=" " >
    [Error Message]
    </wcm:setContext>

    Parameter Details
    location This sets the context of the location of a path string. Either:

      location="query"
      The context is obtained from the query parameter.

      location="request"
      The context is obtained from the value of the request.

      location="session"
      The context is obtained from the value of the current session.

      location="portalContext"
      This is used to define the path of a site area or content item that will be used as the current context of a page. For example: /library1/sitearea3/content4

      location="portalMapping"
      This is used to define the path of a site area or content item that will be used as the default site area of a page. For example: /library1/sitearea3

    wcmWebAppPath The URL up to the web application. For example: http://localhost:10040/wps/wcm
    wcmServletPath The servlet path to the WCM servlet. For example: /connect
    param The name of the parameter the path string will be in.
    project The name of the project to set in the context. If the corresponding project cannot be found, it will be ignored and an error will be logged. An empty string is used to clear any project previously set in the context.
    defaultPath If the location parameter does not resolve to a valid location, then the value of the defaultPath is used. For example: /library2/sitearea1

    The project, wcmWebAppPath , wcmServletPath, and defaultPath parameters are optional. However, if wcmWebAppPath is specified, wcmServletPath must also be specified.

    Developers can add context tags at any place in the page and it will change the context for the rest of the page execution, but the tags cannot be nested.


    Render tags

    These are equivalent to element and component tags.

      Render an element from the current site area, or content item

      <wcm:contentComponent type=" " key=" " > [Error Message] </wcm:contentComponent>

      Parameter Details
      type This determines where the element is being referenced from. Either content or sitearea.
      key The name of the element being referenced.

      <wcm:libraryComponent name=" " library=" " >
          [Error Message]
      </wcm:libraryComponent >

      Render a component from the Component Library

      Parameter Details
      name Component being referenced.
      library The name of the library where the component is stored.
      For example:

      <wcm:libraryComponent name="SC Menu Events" 
              library="Showcase" />  
          We do not have access to this item.  
      </wcm:libraryComponent >

      Render Content based on the current context of a page
      <wcm:content pageDesign=" " >
          [Error Message]
      </wcm:content >

      Parameter Details
      pageDesign This name of the Presentation Template used to determine context. Optional.


    Error handling

    The following tag can be added to error messages to enable error handling:

      <%=error%>


    Plugin tag

    Render plug-ins can be referenced within JSP code using a plugin tag:

    < wcm:plugin name=" " 
            param1="value" 
            param2="value2" >
         // Your text.
     </wcm:plugin>


    Parent The IBM Web Content Manager API