Exemple : Utilisation de la bibliothèque de balises d'agrégation des portlets
La bibliothèque des balises d'agrégation vous permet d'agréger plusieurs portlets pour avoir des contenus multiples et différents sur une même page. La bibliothèque peut être utilisée par tout fichier JSP (JavaServer Pages) inclus par un servlet.
Pour utiliser la bibliothèque de balises d'agrégation des portlets, vous devez déclarer le tag-lib en haut du fichier JSP file à l'aide de <%@ taglib uri="http://ibm.com/portlet/aggregation" prefix="portlet" %> comme dans l'exemple suivant. L'exemple de fichier JSP suivant illustre comment agréger des portlets sur une 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"/>
<!-- Cette table est la table extérieure pour la création de présentation de portail à deux colonnes -->
<TABLE border="0" CELLPADDING="3" CELLSPACING="8" WIDTH="100%">
<TR>
<TD VALIGN="top">
<!-- Cette table est le portlet supérieur dans la première colonne -->
<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/>
<!-- Cette table est le portlet inférieur dans la première colonne -->
<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">
<!-- Cette table est le portlet supérieur dans la deuxième colonne -->
<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>
Vous pouvez inclure la formatage suivant dans
le fichier JSP de l'exemple précédent immédiatement après la déclaration de la bibliothèque de balises.<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>