The Portlet Tag Library (PTL) enables JSPs that are included from portlets to have direct access to portlet specific elements such as the RenderRequest and RenderResponse. It also provides JSPs with access to portlet functionality such as creating portlet URLs.
The defineObjects tag defines the following variables in the JSP page:
● RenderRequest renderRequest
● RenderResponse renderResponse
● PortletConfig portletConfig
The tag cannot define attributes and it cannot have a body.
The following code sets the title of a portlet:
<portlet:defineObjects/>
<% renderResponse.setTitle("my portlet title"); %>
The actionURL tag creates a URL that points to the current portlet and triggers an action request with the supplied parameters. You can add parameters to the URL using the param tag between the actionURL start and end tags. The tag defines the following non-required attributes:
● windowState
Indicates the window state the portlet should have after the URL is executed. There are three predefined states: minimized, normal, and maximized.
● portletMode
Indicates the portlet mode the portlet should have after the URL is executed. There are three predefined states: view, edit, and help.
● var
Represents the exported scoped variable for the action URL written to the JSPWriter.
● secure
Indicates if the URL is a secure or insecure connection, set using secure=true or secure=false.
The following code sets the portlet into maximized state and edit mode to edit departments:
<portlet:actionURL windowState=”maximized” portletMode=”edit”>
<portlet:param name=”action” value=”editDepartments”/>
</portlet:actionURL>
The renderURL tag creates a URL that points to the current portlet and triggers a render request with the supplied parameters. You can add parameters to the URL using the param tag between the renderURL start and end tags. The tag defines the following non-required attributes:
● windowState
Indicates the window state the portlet should have after the URL is executed. There are three predefined states: minimized, normal, and maximized.
● portletMode
Indicates the portlet mode the portlet should have after the URL is executed. There are three predefined states: view, edit, and help.
● var
Represents the exported scoped variable for the action URL written to the JSPWriter.
● secure
Indicates if the URL is a secure or insecure connection, set using secure=true or secure=false.
The following code sets the portlet to maximized state and view mode to show data for two employees:
<portlet:renderURL portletMode=”view” windowState=”maximized”>
<portlet:param name=”showEmployee” value=”emp1”/>
<portlet:param name=”showEmployee” value=”emp2”/>
</portlet:renderURL>
The namespace tag defines a unique value for the current portlet and ensures that no naming conflicts occur with other parts of the portal page. You use the namespace tag for named elements. The tag has no body content.
The param tag defines parameters to be added to the actionURL or the renderURL and has no body content. It has two required attributes:
● name – represents the name of the parameter to add to the URL.
● value – represents the value of the parameter associated with the given name.
<portlet:param name=”employeeName” value=”DeniseSmith”/>
To use the PTL in your JSPs, you declare the tag library in the following way:
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
The following creates a render URL to provide a link to the portlet that includes the JSP, and sets its mode to VIEW and its window state to NORMAL:
<portlet:renderURL portletMode="view" windowState="normal">
<portlet:param name="employeeFirstName" value="Denise"/>
<portlet:param name="employeeLastName" value="Smith"/>
</portlet:renderURL>