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

 
在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){}

%>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值