WebSphere Portal 6平台porlet skin中获取portletID和porletTitle的方法

来源:互联网 发布:嵌入式系统编程 编辑:程序博客网 时间:2024/06/06 14:10
 
在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){}

%>
原创粉丝点击