WAS v8.5 > End-to-end paths > Portlet applicationsTasks: Managing portlets
We can use this task to manage deployed portlet applications.
Before beginning this task, you must have a portlet application installed. See Install enterprise application files for additional information.
We can complete the following steps to manage portlets.
- Render a portlet.
- Access a single portlet using URL addressability.
- Access multiple portlets using Portlet aggregation using JSP.
- Change the location of Portlet preferences. By default, portlet preferences for each portlet window are stored in a cookie. However, we can change the location of where to store portlet preferences.
- Disable URL addressability. By default, we can access a portlet through an URL, however, we can disable this feature.
- Enable portlet fragment caching.
Portlet fragment caching is disabled by default.
Example
An asynchronous bean method can use the connections that its creating Java EE component obtained using java:comp resource references.
- Use the portlet aggregation tag library
- Configure the extended portlet deployment descriptor to disable PortletServingServlet
Use the portlet aggregration tag library. We can use the aggregation tag library to aggregate multiple portlets to have multiple and different content on one page. The library can be used by every JSP file that has been included by a servlet.To use the portlet aggregation tag library, you must declare the tag-lib at the top of the JSP file using, <%@ taglib uri="http://ibm.com/portlet/aggregation" prefix="portlet" %>, as in the following example. The following JSP file example shows how to aggregate portlets on one page. We can use the aggregation tag library to aggregate multiple portlets to have multiple and different content on one page. The library can be used by every JSP file that has been included by a servlet.
class GoodAsynchBean { DataSource ds; public GoodAsynchBean() throws NamingException { // ok to cache a connection factory or datasource // as class instance data. InitialContext ic = new InitialContext(); // it is assumed the created Java EE component has this // resource reference defined in its deployment descriptor. ds = (DataSource)ic.lookup("java:comp/env/jdbc/myDataSource"); } // When the asynchronous bean method is called, get a connection, // use it, then close it. void anEventListener() { Connection c = null; try { c = ds.getConnection(); // use the connection now... } finally { if(c != null) c.close(); } }}The following example illustrates an asynchronous bean that uses connections incorrectly:
class BadAsynchBean { DataSource ds; // Do not do this. We cannot cache connections across asynch method calls. Connection c; public BadAsynchBean() throws NamingException { // ok to cache a connection factory or datasource as // class instance data. InitialContext ic = new InitialContext(); ds = (DataSource)ic.lookup("java:comp/env/jdbc/myDataSource"); // here, you broke the rules... c = ds.getConnection(); } // Now when the asynch method is called, illegally use the cached connection // and you likely see J2C related exceptions at run time. // close it. void someAsynchMethod() { // use the connection now... }}
Configure the extended portlet deployment descriptor to disable PortletServingServlet. Portlet URL serving supports direct access to all functions and states of a portlet by creating the appropriate URLs. In a production setup where the portlet is served through an enterprise portal application that applies its own access control, is considered a security risk. By setting the portletServingEnabled property to false, an administrator can ensure that a sensitive portlet is never accessed by direct URL serving.Extensions for the portlet deployment descriptor are defined within a file called ibm-portlet-ext.xmi. This deployment descriptor is an optional descriptor used to configure WebSphere extensions for the portlet application and its portlets. For example, we can disable the PortletServingServlet servlet for the portlet application in the extended portlet deployment descriptor.
The ibm-portlet-ext.xmi extension file is loaded during application startup. If there are no extension files specified with this setting, the default values of the portlet container are used.
The default for the portletServingEnabled attribute is true. The following is an example of how to configure the application so that a PortletServingServlet servlet is not created for any portlet on the portlet application.
<?xml version="1.0" encoding="UTF-8"?> <portletappext:PortletApplicationExtension xmi:version="1.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:portletappext="portletapplicationext.xmi" xmlns:portletapplication="portletapplication.xmi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmi:id="PortletApp_ID_Ext" portletServingEnabled="false"> <portletappext:portletApplication href="WEB-INF/portlet.xml#myPortletApp"/> </portletappext:PortletApplicationExtension>
Subtopics
- Portlets
Portlets are reusable web modules that provide access to Web-based content, applications, and other resources. Portlets can run on the application server because it has an embedded JSR 286 Portlet container. The JSR 286 API provides backwards compatibility. We can assemble portlets into a larger portal page, with multiple instances of the same portlet displaying different data for each user.- Portlet container
The portlet container is the runtime environment for portlets using the JSR 286 Portlet specification, in which portlets are instantiated, used, and finally destroyed. The JSR 286 Portlet API provides standard interfaces for portlets and backwards compatibility for JSR 168 portlets. Portlets that are based on this JSR 286 Portlet Specification are referred to as standard portlets.- Portlet container settings
Use this page to manage the portlet container of this application server.- Portlet aggregation using JSP
The aggregation tag library generates a portlet aggregation framework to address one or more portlets on one page If we write JSP, we can aggregate multiple portlets on one page using the aggregation tag library. This tag library does not provide full featured portal aggregation implementation, but provides a good migration scenario if you already have aggregating servlets and JSP and want to switch to portlets.- URL addressability
We can request a portlet directly through a URL to display its content without portal aggregation. The PortletServingServlet servlet registers each web application containing portlets. It is similar to the FileServingServlet servlet of the web container that serves resources. The PortletServingServlet servlet supports direct rendering of portlets into a full browser page by a URL request.- Portlet preferences
Preferences are set by portlets to store customized information. By default, the PortletServingServlet servlet stores the portlet preferences for each portlet window in a cookie. However, we can change the location to store them in either a session, an .xml file, or a database.- Example: Configuring the extended portlet deployment descriptor to disable PortletServingServlet
Portlet URL serving supports direct access to all functions and states of a portlet by creating the appropriate URLs. In a production setup where the portlet is served through an enterprise portal application that applies its own access control, is considered a security risk. By setting the portletServingEnabled property to false, an administrator can ensure that a sensitive portlet is never accessed by direct URL serving.- Converting portlet fragments to an HTML document
A portlet only delivers fragment output whereas a servlet typically delivers document output. However, we can use the PortletServingServlet servlet, which is similar to the FileServingServlet servlet, to address portlets like servlets.- Portlet container custom properties
We can configure name-value pairs of data, where the name is a property key and the value is a string value used to set internal system configuration properties. Defining a new property enables you to configure a setting beyond that which is available in the dmgr console. The following is a list of the available Portlet container custom properties.- Portlet and PortletApplication MBeans
The MBeans of type portlet and portletapplication provide information about a given portlet application and its portlets. Through the MBean of type portletapplication, we can retrieve a list of names of all portlets that belong to a portlet application. By querying the MBean of type portlet with a given portlet name, we can retrieve portlet specific information from the MBean of type portlet.- Portlet URL security
WAS enables direct access to portlet Uniform Resource Locators (URLs), just like servlets. This section describes security considerations when accessing portlets using URLs.
Related
View deployment descriptors