Web Content Manager JSP tags

You use IBM® Web Content Manager JSP tags with the Web Content Manager API to pull Web Content Manager content and components into external JSP applications.

Note: A JSP referenced within a JSP component must not include a reference, directly or indirectly, to the same JSP component. This includes references within Web Content Manager tags or the API. If it does, a loop is created and your server will crash.
Note: To use the Web Content Manager JSP tags, the following directive must be provided in the JSP:
<%@ taglib uri="/WEB-INF/tld/wcm.tld" prefix="wcm" %>
Storing JSP Files:

JSP files can be located:

  • within the was_profile_root/installedApps/node-name/wcm.ear/ilwwcm.war directory of your server.

    The JSP page is also stored in the client war directory of the local rendering portlet or of the servlet or portlet that calls the JSP, if using the Web Content Manager API. For example, to render a JSP page on a local rendering portlet, you would also need to store a copy of the JSP file under was_profile_root/installedApps/node-name/PA_WCMLocalRendering.ear/ilwwcm-localrende.war

  • within any other web application running on portal. When referencing JSP files in another web application, use the following path: contextPath;jspPath

    For example: /wps/customapplication;/jsp/editor.jsp

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 you update a JSP file, you may need to wait for it to be reloaded before your changes will be displayed.

InitWorkspace tag

This is used to 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=" " user=" " password=" " >
[Error Message]
</wcm:initworkspace>
Table 1. Parameters
Parameter Details
username The user name of a valid Web Content Manager user.
user This parameter is used to specify a java.security.Principal object instead of the username.
password The password for the valid Web Content Manager username or user.
Note: Username, user, and password are optional. If not specified, the current user will be used instead, including the anonymous user.
This is an example use of this tag:
<%@ 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

This sets the path to your Web Content Manager server. This is not required in JSP that is displayed via a JSP component.

<wcm:setExplicitContext wcmWebAppPath=" " wcmServletPath=" " path=" "
 requestParameters" " prefix=" " project=" " >
[Error Message]
</wcm:setExplicitContext>
Table 2. Parameters
Parameter Details
wcmWebAppPath The URL up to the web application. For example: http://localhost:10040/wps/wcm
wcmServletPath The servlet path to the Web Content Manager servlet. For example: /connect
path The path to the content and site areas. For example: /Site Area A/ Site Area B/Content C
requestParameters You specify java Map request parameters to set in the context. These parameters can be used by menu components that are 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.
Note: 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 that is displayed via a JSP component.

<wcm:setContext location=" "  wcmWebAppPath=" " wcmServletPath=" " param=" " project=" " defaultPath=" " >
[Error Message]
</wcm:setContext>
Table 3. Parameters
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 Web Content Manager servlet. For example: /connect
param This is the name of the parameter that 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
Note: 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.

Rendering tags

These are equivalent to element and component tags.

Rendering an element from the current site area, or content item
<wcm:contentComponent type=" " key=" " >
[Error Message]
</wcm:contentComponent>
Table 4. Parameters
Parameter Details
type This determines where the element is being referenced from. Either content or sitearea.
key This is the name of the element being referenced.
<wcm:libraryComponent name=" " library=" " >
[Error Message]
</wcm:libraryComponent >
Rendering a component from the Component Library
Table 5. Parameters
Parameter Details
name This is the name of the component being referenced.
library This is the name of the library where the component is stored.
For example:
<wcm:libraryComponent name="SC Menu Events" library="Showcase" /> 
You do not have access to this item.
</wcm:libraryComponent >
Rendering Content based on the current context of a page
<wcm:content pageDesign=" " >
[Error Message]
</wcm:content >
Table 6. Parameters
Parameter Details
pageDesign This name of the Presentation Template used to determine context. This parameter is optional.

Error handling

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

<%=error%>

Plugin tag

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

<wcm:plugin name=" " param1="value" param2="value2" >

// Your text.

</wcm:plugin>
See Creating a plug-in tag for further information.