在portlet skin的Control.jsp中:
通过如下方式可获得portletID和portletTitle并输出到HTML中:
导入以下taglib
<%@ taglib uri = "http://www.ibm.com/xmlns/prod/websphere/portal/v6.0/portal-skin" prefix="portal-skin" %>
//获取portletID
<portal-skin:portletID />
//获取当前语言区域的portletTitle
<portal-skin:portletTitle>
<portal-fmt:problem bundle="nls.problem" />
</portal-skin:portletTitle>
通过如下方式可获得portletID和portletTitle并将他们赋值给某个Java变量:
//获取portletID并赋值
<portal-skin:portletID var="myPortletID"/>
<jsp:useBean id="myPortletID" class="java.lang.String" scope="page"/>
<%
//赋值后便可以使用了
String s = myPortletID;
%>
//获取默认语言区域(EN)的portletTitle并赋值
<portal-skin:portletTitle id="myPortletTitle"/>
次标签将编译成:
String myPortletTitle = doSomeThingAndGetCurrentPortletTitle();
通过如下方法可以编程获得porletTitle:
<%!
private static com.ibm.portal.identification.Identification identification;
public void jspInit(){
try{
/* only perform this JNDI lookup once as this is an expensive call performance wise */
javax.naming.Context ctx=new javax.naming.InitialContext();
identification=(com.ibm.portal.identification.Identification) ctx.lookup("portal:service/Identification");
} catch (javax.naming.NamingException ne){
ne.printStackTrace();
}
}
%>
<%
//Fetch currentLayoutNode
String currentLayoutNodeStr = "";
LayoutNode currLayoutNode = null;
if (pageContext.getAttribute("currentLayoutNode", pageContext.REQUEST_SCOPE) != null) {
currLayoutNode=(LayoutNode)pageContext.getAttribute("currentLayoutNode", pageContext.REQUEST_SCOPE);
currentLayoutNodeStr=identification.serialize(currLayoutNode.getObjectID());
} else {
currLayoutNode=(LayoutNode)pageContext.getRequest().getAttribute("com.ibm.wps.composition.element");
currentLayoutNodeStr=identification.serialize(currLayoutNode.getObjectID());
}
// Fetch Portlet Title
String currentNodeTitle = "";
com.ibm.portal.content.LayoutControl lControl =
(com.ibm.portal.content.LayoutControl) currLayoutNode;
com.ibm.portal.ObjectID portletDefOID = null;
try {
javax.naming.Context ctx2 = new javax.naming.InitialContext();
com.ibm.portal.model.LocalizedStringResolver localizedStringResolver =
(com.ibm.portal.model.LocalizedStringResolver) ctx2.lookup("portal:service/model/LocalizedStringResolver");
currentNodeTitle = localizedStringResolver.getTitle(lControl, request.getLocales());
} catch (javax.naming.NamingException ne){}
%>
private static com.ibm.portal.identification.Identification identification;
public void jspInit(){
try{
/* only perform this JNDI lookup once as this is an expensive call performance wise */
javax.naming.Context ctx=new javax.naming.InitialContext();
identification=(com.ibm.portal.identification.Identification) ctx.lookup("portal:service/Identification");
} catch (javax.naming.NamingException ne){
ne.printStackTrace();
}
}
%>
<%
//Fetch currentLayoutNode
String currentLayoutNodeStr = "";
LayoutNode currLayoutNode = null;
if (pageContext.getAttribute("currentLayoutNode", pageContext.REQUEST_SCOPE) != null) {
currLayoutNode=(LayoutNode)pageContext.getAttribute("currentLayoutNode", pageContext.REQUEST_SCOPE);
currentLayoutNodeStr=identification.serialize(currLayoutNode.getObjectID());
} else {
currLayoutNode=(LayoutNode)pageContext.getRequest().getAttribute("com.ibm.wps.composition.element");
currentLayoutNodeStr=identification.serialize(currLayoutNode.getObjectID());
}
// Fetch Portlet Title
String currentNodeTitle = "";
com.ibm.portal.content.LayoutControl lControl =
(com.ibm.portal.content.LayoutControl) currLayoutNode;
com.ibm.portal.ObjectID portletDefOID = null;
try {
javax.naming.Context ctx2 = new javax.naming.InitialContext();
com.ibm.portal.model.LocalizedStringResolver localizedStringResolver =
(com.ibm.portal.model.LocalizedStringResolver) ctx2.lookup("portal:service/model/LocalizedStringResolver");
currentNodeTitle = localizedStringResolver.getTitle(lControl, request.getLocales());
} catch (javax.naming.NamingException ne){}
%>
本文介绍了如何在portletskin的Control.jsp中通过特定标签获取portlet的ID和标题,并将其输出到HTML页面或赋值给Java变量的方法。同时,还提供了一种编程方式来获取portlet的标题。
1577

被折叠的 条评论
为什么被折叠?



