Example: Use the portlet aggregation 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 (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.
<%@ taglib uri="http://ibm.com/portlet/aggregation" prefix="portlet" %> <%@ page isELIgnored="false" import="java.util.Enumeration"%> <portlet:init portletURLPrefix="/dummy/portletTagTest/" portletURLSuffix="/more" portletURLQueryParams="p1=v1&p2=v2"> <portlet:insert url="worldclock/StdWorldClock" contentVar="worldclockcontent" titleVar="worldclocktitle"/> <portlet:state url="worldclock/StdWorldClock" portletMode="view" var="worldclockview" portletWindowState="maximized"> <portlet:urlParam name="namea" value="valuea"/> <portlet:urlParam name="nameb" value="valueb"/> </portlet:state> <portlet:state url="worldclock/StdWorldClock" portletMode="edit" var="worldclockedit" portletWindowState="normal"> <portlet:urlParam name="name1" value="value1"/> <portlet:urlParam name="name2" value="value2"/> </portlet:state> <portlet:state url="worldclock/StdWorldClock" portletMode="view" var="worldclockmin" portletWindowState="minimized"> <portlet:urlParam name="namemin" value="valuemin"/> <portlet:urlParam name="namemin" value="valuemin"/> </portlet:state> <portlet:insert url="worldclock/StdWorldClock" windowId="min" contentVar="simplecontent" titleVar="simpletitle"/> <portlet:state url="worldclock/StdWorldClock" windowId="min" portletMode="view" var="simpleview" portletWindowState="maximized"> <portlet:urlParam name="name3" value="value3"/> <portlet:urlParam name="name4" value="value4"/> <portlet:urlParam name="name5" value="value5"/> <portlet:urlParam name="name5" value="value5a"/> <portlet:urlParam name="name5" value="value5b"/> <portlet:urlParam name="name5" value="value5c"/> </portlet:state> <portlet:state url="worldclock/StdWorldClock" windowId="min" portletMode="edit" var="simpleedit" action="true" portletWindowState="normal"> <portlet:urlParam name="name6" value="value6"/> <portlet:urlParam name="name6" value="value6z"/> </portlet:state> <portlet:state url="worldclock/StdWorldClock" windowId="min" portletMode="view" var="simplemin" portletWindowState="minimized"> <portlet:urlParam name="name1" value="value1"/> <portlet:urlParam name="name2" value="value2"/> </portlet:state> <portlet:insert url="test/TestPortlet1" contentVar="testcontent" titleVar="testtitle"/> <portlet:state url="test/TestPortlet1" portletMode="view" var="testview" portletWindowState="maximized"/> <portlet:state url="test/TestPortlet1" portletMode="edit" var="testedit" portletWindowState="maximized"/> <!-- This table is the outtermost table for creating two-column portal layout --> <TABLE border="0" CELLPADDING="3" CELLSPACING="8" WIDTH="100%"> <TR> <TD VALIGN="top"> <!-- This table is the top portlet in the first column --> <table border="0" width="100%" CELLPADDING="3" CELLSPACING="0" CLASS="portletTable" SUMMARY="portlet top left"> <tr><td class="portletTitle" NOWRAP>worldclock title:${worldclocktitle}</td> <td CLASS="portletTitleControls" NOWRAP> <a href="${worldclockview}">view</a> <a href="${worldclockedit}">edit</a> <a href="${worldclockmin}">minimize</a> </td> </tr> <tr> <td CLASS="portletBody" COLSPAN="2"> ${worldclockcontent} </td> </tr> </table> <BR/> <!-- This table is the bottom portlet in the first column --> <table border="0" width="100%" CELLPADDING="3" CELLSPACING="0" CLASS="portletTable" SUMMARY="portlet bottom left"> <tr> <td class="portletTitle" NOWRAP>test title:${testtitle}</td> <td CLASS="portletTitleControls" NOWRAP> <a href="${testview}">view</a> <a href="${testedit}">edit</a> </td> </tr> <tr> <td CLASS="portletBody" COLSPAN="2"> ${testcontent} </td> </tr> </table> </TD> <TD VALIGN="top"> <!-- This table is the top portlet in the second column --> <table border="0" width="100%" CELLPADDING="3" CELLSPACING="0" CLASS="portletTable" SUMMARY="portlet top right"> <tr> <td class="portletTitle" NOWRAP>simple title:${simpletitle}</td> <td CLASS="portletTitleControls" NOWRAP> <a href="${simpleview}">view</a> <a href="${simpleedit}">edit</a> <a href="${simplemin}">minimize</a> </td> </tr> <tr> <td CLASS="portletBody" COLSPAN="2"> ${simplecontent} </td> </tr> </table> </TD> </TR> </table> </portlet:init>We can include the following formatting to the previous example JSP file immediately once we have declared the tag library.<STYLE TYPE="TEXT/CSS"> BODY { font-family:Verdana,sans-serif; font-size:70% } .portletTitle { text-align: left;border-top: #000000 1px solid; border-bottom: #000000 1px solid; FONT-SIZE: 60.0%; COLOR: #ffffff; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #5495d5; } .portletTitleControls { text-align: right;border-top: #000000 1px solid; border-right: #000000 1px solid; border-bottom: #000000 1px solid; FONT-SIZE: 60.0%; COLOR: #ffffff; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #5495d5; } .portletTitleControls A { COLOR: #ffffff; text-decoration:none; border:#5495d5 1px solid;border-left:white 1px solid; padding-left:0.5em; padding-right:0.5em; } .portletTitleControls A:hover { COLOR: #ffffff; text-decoration:none; border-top:white 1px solid; border-bottom:white 1px solid;border-right:white 1px solid; } .minimizeControl { font-weight:bold; font-size:100%; } .portletTable { border-left: gray 1px solid; border-bottom: gray 1px solid; border-right: gray 1px solid; } .portletBody { font-family:Verdana,sans-serif; font-size:70% } </STYLE>
Related tasks
Task overview: Managing portlets
Aggregation tag library attributes Portlet aggregation using JSP