![]() ![]() ![]() ![]() ![]() ![]() |
Display templates allow you to create standard views for portal content that you can use within your JSPs using display template JSP tags. For example, if your portal displays a list of books, you can create display templates that determine how the list of books is presented. Or you can create display templates that configure how an employee directory of pictures are presented.
Content management features such as the Content Presenter portlet and syndication feeds use display templates to present content to users. You can customize these templates or add new ones to extend these features.
This chapter includes the following topics:
You use display template JSP tags to call display templates within your portal. Display templates are JSPs that you create that dictate how content is presented. After creating a display template, you register it with a wlp-template-config.xml
file. After a display template (JSP) has been created and registered correctly, you can use it within a JSP using display template JSP tags.
WebLogic Portal provides two types of display template tags:
For more information about display template JSP tags, see the Commerce and Interaction Management JSP Tag Javadoc.
Before using a display template JSP tag, you must do the following:
Display templates are JSP pages that you use in conjunction with display template JSP tags to display associated resources. These JSPs can incorporate any JSP functionality you require. You can use display templates to display repository content or other portal content, such as JSPs.
Tip: | As a best practice, it is helpful to store all display templates in the same directory in your web application. |
You can create two types of display templates in your portal; each are registered differently and associated with the respective JSP tag.
Within the wlp-template-config.xml
file, there are two "root" elements used to register display templates:
You can create multiple display template JSPs for the same resource. Typically, you create multiple views for displaying the same content type with a content display template. For example, you can create a JSP that displays a thumbnail image and another JSP that displays a full image. You can also assign a default view to use for a resource. You then register each template as a view within the wlp-template-config.xml
file. Each template you register must have at least one view. Listing 11-3 gives an example of a content display template tag that uses a particular view.
It is possible to re-use templates within other templates by incorporating a template JSP tag within your JSP. By re-using display templates in this way, you can reduce the amount of code you need to maintain. For example, Content Presenter templates use display templates to display content within the Content Presenter portlet and re-use the same content display template whenever possible. The content display template contains the code needed to retrieve the content node. In this case, if you want to change what content is retrieved (such as including a new property), you need only update the content display template.
Tip: | A content display template is associated with a particular content type. |
After creating a display template, you must create a configuration file that associates the template (JSP page) that you created with the respective resource. For example, if you have created a view to use with a content type, you must register that relationship using a wlp-template-config.xml
file.
To create a new wlp-template-config.xml
file using WorkSpace Studio:
/<WebProject>/WEB-INF
folder and select New > Other.wlp-template-config.xml
for the name of the new file and click Next. Be sure the file is located in the WEB-INF directory of your web project.http://www.bea.com/ns/p13n/90/wlp-template-config.xml
and click Next.wlp-template-config.xml
file, right-click it and select Open With > XML Editor (or the editor of your choice) to edit the file. Use the following examples to assist you when editing the file.wlp-template-config.xml
schema.wlp-template-config.xml
file.<wlp-template-config><!-- Describes the content repository's types and templates -->
<content-repository>
<!-- Name of repository. (Required) -->
<name> </name>
<!-- Optionally, used to define a namespace for this set of templates.-->
<content-name-space>
<!-- Description for developer use, not shown to end user (Optional) -->
<description> </description>
<!-- If only the repository that matches this template is used to render
content (Optional) -->
<default-template-uri> </default-template-uri>
<!-- Describes the content type -->
<content-resource>
<!-- Description not shown to end user (Optional) -->
<description> </description>
<!-- Name of content type.(Required) -->
<name> </name>
<!-- If only the content type matches, this template is used to
render content. Contains the URI to the JSP location. (Optional) -->
<default-template-uri> </default-template-uri>
<!-- Describes the view (Optional) -->
<view>
<!-- Name of the view (Required) -->
<name> </name>
<!-- Description not shown to end user (Optional) -->
<description> </description>
<!-- If the view name that matches, this template is used to
render content. Contains the URI to the JSP location.
(Required) -->
<uri> </uri>
</view>
</content-resource>
</content-name-space>
</content-repository>
<!-- Describes templates that are not linked to a content repository --!>
<template-group>
<name></name>
<!-- Optional. Allows you to namespace your templates for organizational
purposes. If creating templates for the Content Presenter, use
wlp-content-presenter-multiple or wlp-content-presenter-single.--!>
<template-name-space>
<name></name>
<template>
<description> </description>
<!-- (Required)Name of template. This name displays as the Template
Category name within the Content Presenter portlet. --!>
<name></name>
<!-- Enter a default template URI. If your template definition
contains no view elements, then this element is mandatory or the
template will not work with the Content Presenter. --!>
<default-template-uri> </default-template-uri>
<!-- Optionally, specific a preview icon for this template --!>
<default-template-preview-icon-uri>
</default-template-preview-icon-uri>
<view>
<name> </name>
<description> </description>
<uri> </uri>
<!--Optionally, specify a preview icon for this view --!>
<preview-icon-url></preview-icon-url>
</view>
</template>
</template-name-space>
</template-group>
</wlp-template-config>
Listing 11-2 provides an example of a valid wlp-template-config.xml
file.
<wlp-template-config>
<content-repository>
<name>MyRepo</name>
<default-template-uri>/MyDefault.jsp </default-template-uri>
<content-resource>
<name>thumbnail</name>
<view>
<name>small</name>
<uri>/smallview.jsp</uri>
</view>
</content-resource>
<content-resource>
<name>Product</name>
<default-template-uri>/MyProductDisplay.jsp</default-template-uri>
<view>
<name>small</name>
<uri>/product/smallview.jsp</uri>
</view>
</content-resource>
<content-resource>
<name>Camera </name>
<default-template-uri>
/MyCameraProductDisplay.jsp
</default-template-uri>
<view>
<name>small</name>
<uri>/product/camera/smallview.jsp</uri>
</view>
</content-resource>
</content-repository>
</wlp-template-config>
The <dt:displaycmtemplate>
is used to display content from your content repository. Content display templates are associated with content types and can have multiple views. See the
Commerce and Interaction Management JSP Tag Javadoc for more information about this tag and its attributes.
This example displays a content type of DigitalCamera which extends Camera which extends Product. See <dt:displaycmtemplate> Example Using Type Inheritance for an example of how the tag takes advantage of type inheritance. It consists of three parts:
Tip: | You can define a default view within your configuration file that is used for all content resources that do not have otherwise defined display templates. You do this by defining a content resource with a * as a value. For example, <name>*<name> . See Listing 11-5 for an example. You can also use a * as <name> for the content-repository element. |
Listing 11-3 shows an example JSP tag usage that uses a defined view and how to specify the node with <cm:getNode>
.
<cm:getNode path="/BEA Repository/sampleFolder/sampleNode" id="aNode"/>
<dt:displaycmtemplate repositoryName="MyRepo" resourceName="DigitalCamera" view="small"/>
Listing 11-4 shows an example usage that uses the default view.
<dt:displaycmtemplate repositoryName="MyRepo" resourceName="Camera" view="small"/>
Listing 11-5 provides the corresponding configuration file.
<wlp-template-config>
<content-repository>
<name>MyRepo</name>
<default-template-uri>/MyDefault.jsp </default-template-uri>
<content-resource>
<!-- Using an * in the name element defines a default view for content
resources that do not have registered templates.--!>
<name>*</name>
<view>
<name>small</name>
<uri>/smallview.jsp</uri>
</view>
</content-resource>
<content-resource>
<name>Product</name>
<default-template-uri>/MyProductDisplay.jsp</default-template-uri>
<view>
<name>small</name>
<uri>/product/smallview.jsp</uri>
</view>
</content-resource>
<content-resource>
<name>Camera</name>
<default-template-uri>
/MyCameraProductDisplay.jsp
</default-template-uri>
<view>
<name>small</name>
<uri>/product/camera/smallview.jsp</uri>
</view>
</content-resource>
</content-repository>
</wlp-template-config>
<!-- With this configuration the uri of "product/camera/smallview.jsp" will be
found. This is because the Digital Camera content type inherits from the Camera
content type and the camera <content-resource> has a small view. -->
This example displays a content type of DigitalCamera which extends Camera which extends Product. Notice that the tag leverages type inheritance when searching for which view to use. For more information about type inheritance, see Using Content Type Inheritance.
Listing 11-6 shows the syntax of the JSP tag.
<dt:displaycmtemplate repositoryName="MyRepo" resourceName="DigitalCamera" view="full"/>
Listing 11-7 provides the corresponding configuration file.
<wlp-display-template>
<content-repository>
<name>MyRepo</name>
<default-template-uri>/MyDefault.jsp </default-template-uri>
<content-resource>
<name>Product</name>
<default-template-uri>/MyProductDisplay.jsp</default-template-uri>
<view>
<name>small</name>
<uri>/product/smallview.jsp</uri>
</view>
<view>
<name>full</name>
<uri>/product/fullview.jsp</uri>
</view>
</content-resource>
<content-resource>
<name>Camera</name>
<default-template-uri>
/MyCameraProductDisplay.jsp
</default-template-uri>
<view>
<name>small</name>
<uri>/product/camera/smallview.jsp</uri>
</view>
</content-resource>
</content-repository>
</wlp-display-template>
<!-- With this configuration the uri of "product/fullview.jsp" will be found. This is the JSP tag takes advantage of type inheritance and knows that camera inherits from product. -->
Use the <dt:displaytemplate>
tag to display any non-content management portal resources. For more information about this tag and its attribute, see the
Commerce and Interaction Management JSP Tag Javadoc.
The Content Presenter portlet provides a quick way to show customized content within your portal. With the Content Presenter portlet, any portal user with sufficient rights can change which content is displayed in the portlet. For more information about the Content Presenter portlet and configuration instructions, see Using the Content Presenter Portlet in the Portlet Development Guide.
You can create custom display templates for the Content Presenter portlet. To use custom display templates within Content Presenter, you must register them specifically for Content Presenter within the wlp-template-config.xml
file.
For example, you can create one template to control how the details of a single press release are displayed, and you can create another template to control how a list of multiple press releases are displayed. You allow portlet users to choose different views such as one that displays a summary of the press release, the press release's title only, or an internal view of the press release.
For general information about creating and configuring display templates, see Using Display Template JSP Tags.
Note: | When the user does not have authorization to view the content displayed in the Content Presenter portlet, the default behavior is to ignore the error and display an empty portlet. As the template designer, if you want to display a message instead, you must create the required logic in the template for handling the Authorization Exception. |
Content display templates cannot be used directly in Content Presenter.
However, you can use content display templates within your Content Presenter templates. By calling content display templates within a display template JSP, you can re-use code for different presentation styles.
Tip: | The Content Presenter portlet uses generic display templates within its implementation that are called by the <dt:displaytemplate> JSP tag. Content display templates are called with the <dt:displaycmtemplate> JSP tag; therefore they cannot be used directly by the Content Presenter portlet. |
Using content display templates is optional and can make your template configuration more complicated. However, when you re-use content display templates within your Content Presenter templates, you can take advantage of content type inheritance, see <dt:displaycmtemplate> Example Using Type Inheritance.
This section contains an example of adding and configuring two new templates that can be used by the Content Presenter portlet.
First, you create a content display template that retrieves a press release content node and its title. Next you call that template, using the <dt:displaycmtemplate>
tag, from two other display templates that each list the press release titles with different types of bullets. Finally, you register each template for use in the Content Presenter portlet by creating a wlp-template-config.xml
file.
Optionally, you can use content display templates within your display templates to centralize code that retrieves content from your repository. In this example, you create a content display template that retrieves the title of a press release. You can later re-use this content display template in a display template registered for the Content Presenter. This way you avoid duplicating the code in each display template that displays the press release title.
Listing 11-8 shows a content display template JSP file that will be re-used in a display template. Notice the use of the <cm:getProperty>
that is used to retrieve content.
<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://www.bea.com/servers/portal/tags/content" prefix="cm"%>
<cm:getProperty name="title"/>
Each template you create must be registered in the wlp-template-config.xml
. When registering content display templates created for re-use in display templates designed for the Content Presenter portlet, you should include the <content-name-space> element and give it a wlp-content-presenter value, see Listing 11-9.
For more information about how content display templates are registered, see Register Your Templates for Content Presenter Portlet.
Note: | If you want to overwrite an existing content display template that is being used, you can use the Content Display Template Wizard, see Using the Content Display Template Wizard. |
...
<content-repository>
<name>BEA Repository</name>
<content-name-space>
<name>wlp-content-presenter-multiple</name>
<content-resource>
<name>pressRelease</name>
<default-template-uri>
/templates/cm/pressReleaseDefault.jsp
</default-template-uri>
<view>
<name>Press Release Title Only</name>
<description>
This retrieves on the title property of a pressRelease.
</description>
<uri>/templates/cm/pressReleaseTitleOnly.jsp</uri>
</view>
</content-resource>
<content-name-space>
</content-repository>
...
You can design your display templates with all the flexibility allowed by JSPs. The example in this section provides two different display templates (JSPs) that each prepend different bullets in front of a list of press release titles.
Use the <dt:displaycmtemplate>
tag in these JSPs to call the pressReleaseTitleOnly content display template, as described in Creating a Content Display Template to Reuse. This helps minimize template code, enforces common presentation patterns, and allow you to take advantage of content type inheritance. For more information, see <dt:displaycmtemplate> Example Using Type Inheritance.
Listing 11-10 provides an example of template that uses a text bullet to prepend the list of press release titles.
<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://www.bea.com/servers/portal/tags/dt
" prefix="dt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"
prefix="c"%>
<%@ taglib tagdir="/WEB-INF/tags/wlpapps/contentui/templates"
prefix="templateTags"%>
<templateTags:getTemplateNodes var="nodes"/>
<c:forEach items="${nodes}" var="node">
•
<dt:displaycmtemplate
resourceName="${node.objectClass.name}"
view="Press Release Title Only"
** This node is passed to the content display template.**
node="${node}"/>
<br/>
</c:forEach>
Listing 11-11 provides an example of a template that uses a .gif image.
<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://www.bea.com/servers/portal/tags/dt
" prefix="dt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"
prefix="c"%>
<%@ taglib tagdir="/WEB-INF/tags/wlpapps/contentui/templates "prefix="templateTags"%>
<templateTags:getTemplateNodes var="nodes"/>
<c:forEach items="${nodes}" var="node">
<img src="bullet.gif"/>
<dt:displaycmtemplate
resourceName="${node.objectClass.name}"
view="Press Release Title Only"
node="${node}"/>
<br/>
</c:forEach>
You use a wlp-template-config.xml
file to register templates for the Content Presenter Portlet.
When you register templates for the Content Presenter portlet, be sure to include the required elements to ensure the templates are accessible. The values for some of these elements are also shown to users when they use the Content Presenter Configuration Wizard wizard. For example, you must use appropriate namespaces for both the content display templates and display templates to ensure that the templates can be used in Content Presenter.
Listing 11-12 provides a blank example of the configuration elements that are re-used in the Content Presenter Configuration Wizard. See Table 11-1 for detailed information about these required elements.
<template-group>
<name>My Custom Template Category</name>
<template-name-space>
<name>wlp-content-presenter-multiple</name>
<view>
...
</template-name-space>
</template-group>
OR
<template-group>
<name>My Custom Template Category</name>
<template-name-space>
<name>wlp-content-presenter-single</name>
<view>
...
</template-name-space>
</template-group>
Table 11-1 lists the configuration elements specific to configuring a display template for use in the Content Presenter portlet. Listing 11-13 provides an example of these elements as they should appear in the wlp-template-config.xml
file when configuring the new templates used in this example.
Note: | For a complete example of the wlp-template-config.xml , see
Listing 11-1, wlp-template-config.xml, on page 11-5. |
Tip: | Defining multiple views within a template category can help organize your content and make it easier to use the Content Presenter Configuration Wizard. For example, you create a template category called Press Releases that has a <default-template-uri> . You might need several ways to view Press Releases, such as a Press Release Summary, Press Release Title Only, Press Release Public View, and Press Release Internal View. In this case, creating multiple template views under your Press Releases template category is a good solution. For more information about views, see Using Views. |
Listing 11-13 shows a sample wlp-template-config.xml
file that references the content display template created earlier (see Listing 11-8) and both display templates that are used directly by the Content Presenter portlet (see Listing 11-10 and Listing 11-11).
Note: | This example also includes a content display template that cannot be used within the Content Presenter. For more information about using display templates, see Using Display Template JSP Tags. |
<?xml version="1.0" encoding="UTF-8"?>
<wlp-template-config xmlns="http://www.bea.com/ns/p13n/90/wlp-template-config">
<content-repository>
<name>BEA Repository</name>
<!--The following bold section is an example of a content display
template that not been namespaced for Content Presenter use. It can
still be used within a Content Presenter template.-->
<content-resource>
<name>Product</name>
<default-template-uri>
/MyProductDisplay.jsp
</default-template-uri>
<view>
<name>small</name>
<uri>/product/smallview.jsp</uri>
</view>
<view>
<name>full</name>
<uri>/product/fullview.jsp</uri>
</view>
</content-resource>
<!-- The following bold section is an example of the best practice of using
a namespace for a content display template that is re-used within a template
for the Content Presenter portlet. -->
<!-- This name element creates a namespace for this template -->
<content-name-space>
<name>wlp-content-presenter-multiple</name>
<content-resource>
<name>pressRelease</name>
<default-template-uri>
/templates/cm/pressReleaseDefault.jsp
</default-template-uri>
<view>
<name>Press Release Title Only</name>
<description>
This retrieves on the title property of a pressRelease.
</description>
<uri>/templates/cm/pressReleaseTitleOnly.jsp</uri>
</view>
</content-resource>
</content-name-space>
</content-repository>
<!--The following bold section is an example of a display template that is
used directly by the Content Presenter template. It includes a template
group, a template namespace, and also uses the view element to list different
templates associated with this category. Optionally, it includes a preview
icon for both the default template and each view to aid users in selecting
the correct template in the wizard. -->
<template-group>
<name>Custom Template Category</name>
<template-name-space>
<name>wlp-content-presenter-multiple</name>
<template>
<description>
This is the default template for listing Press Releases.
</description>
<name>Press Release List Template</name>
<default-template-uri>
/templates/pressReleaseList.jsp
</default-template-uri>
<default-template-preview-icon-uri>
/templates/images/pressReleaseList.gif
</default-template-preview-icon-uri>
<view>
<name>Press Release Bulleted List - Text</name>
<description>
This lists Press Releases with text bullets.
</description>
<uri>/templates/pressReleaseListBulletText.jsp</uri>
<preview-icon-uri>
/templates/images/pressReleaseListBulletText.gif
</preview-icon-uri>
</view>
<view>
<name>Press Release Bulleted List - Image</name>
<description>
This lists Press Releases with imagebullets.
</description>
<uri>/templates/pressReleaseListBulletImage.jsp</uri>
<preview-icon-uri>
/templates/images/pressReleaseListBulletImage.gif
</preview-icon-uri>
</view>
</template>
</template-name-space>
</template-group>
</wlp-template-config>
In WorkSpace Studio, you can use the Content Display Template Wizard to create new content display templates. The Content Display Template Wizard generates the appropriate JSP and generates a file that registers the template according to the repository and content type you choose.
After creating the content display template, you can customize it (using the JSP editor in WorkSpace Studio, for example). As long you do not change the name of the display template, it remains registered.
The Content Display Template Wizard in WorkSpace Studio uses the <dt:displaycmtemplate>
tag to create content display templates.
Tip: | Templates that you create with the Content Display Template Wizard do not automatically appear in the Content Presenter Configuration Wizard, because the configuration wizard only shows templates that were created with the <dt:displaytemplate> tag. If you created a template with the Content Display Template Wizard, you can make the template appear in the Content Presenter Configuration Wizard by calling the template you created in WorkSpace Studio (<dt:displaycmtemplate> ) from a regular display template (<dt:displaytemplate> ) that you create in the Content Presenter Configuration Wizard. |
You can update content display templates that are referenced in the Content Presenter display templates using the Content Display Template Wizard. If you select a previously registered namespace and view, the content display template you create can be called by existing Content Presenter display templates. For more information about configuring Content Presenter display templates, see Creating New Display Templates for the Content Presenter Wizard.
If you want to change or update the content properties that are retrieved for a Content Presenter display template, you can overwrite an existing view with the Content Display Template Wizard. For example, the wlp-default-list view (WLP Default List) lists the primary property of a content item. If you want to update the wlp-default-list view to list additional properties, you can use the Content Display Template Wizard to create a new JSP (that uses the same view name of wlp-default-list) that includes only the content type properties you select.
To create a content display template in WorkSpace Studio:
Note: | When you use the wizard to create a content display template, you can either access the content types and properties on your server or enter them manually if you do not have access to the server. |
Note: | The Content Display Template Wizard does not support nested or linked content properties. If you want to use these properties in your template, you need to manually edit the content display template JSP. |
If you are not running a server:
Table 11-2 lists the content display template views available in WorkSpace Studio. These template views are not automatically visible in the Content Presenter Configuration Wizard, unless you perform additional steps (see the TIP at the end of this section).
Lists all properties of the content item in a syndication feed. For more information, see Creating the Syndicated Feed JSPs.
|
|
Note: | You must have added the Content Presenter facet to your web project in order to access the Content Presenter template views. For more information about the Content Presenter portlet, see the Portlet Guide. |
The template and view configuration information is stored in the wlp-template-config.xml
file and the new JSP is created.
Tip: | Templates that you create with the Content Display Template Wizard in WorkSpace Studio do not automatically appear in the Content Presenter Configuration Wizard, because the configuration wizard only shows templates that were created with the <dt:displaytemplate> tag. If you created a template with WorkSpace Studio's Content Display Template Wizard, you can make the template appear in the Content Presenter Configuration Wizard by calling the template you created in WorkSpace Studio (<dt:displaycmtemplate> ) from a regular display template (<dt:displaytemplate> ) that you create in the Content Presenter Configuration Wizard. |
![]() ![]() ![]() |