天天看點

(Portal 開發讀書筆記)Portlet間互動-使用public render參數

Portlet之間互動,如果資料隻是一些字元串的話,可以使用Public Render參數。

渲染參數有兩種:public和private

private渲染參數用于同一個Portlet的表單或者URL連結等動作激起Portlet容器調用該Portlet的渲染方法。它的生命周期由Portlet容器控制,當render完畢後銷毀。

public渲染參數用于同一個(或者不同)的Portlet應用之間的Portlet的渲染請求,它是private渲染參數的概念的外延。是以隻要正常定義一個private渲染參數,并且聲明它是public 就可以了。它的生命周期和private渲染參數不同,容器無法控制其生命周期,僅僅當顯式調用ActionResponse或者EventResponse的removePublicRenderParameter方法時才能将其銷毀。

在發送者Portlet的部署描述檔案中:

<portlet-app...> 

<portlet> 

<portlet-name>bookCatalog</portlet-name> 

<portlet-class> 

chapter11.code.listing.base.BookCatalogPortlet 

</portlet-class> 

... 

<supported-public-render-parameter> 

recentBookIsbn 

</supported-public-render-parameter> 

</portlet> 

<public-render-parameter> 

<identifier>recentBookIsbn</identifier> 

<qname xmlns:n="http://www.mynamespace.com/"> 

n:myBookISBN 

</qname> 

</public-render-parameter> 

</portlet-app> 

<supported-public-render-parameter>元素用于定義這個Portlet所支援的public渲染參數,而<public-render-parameter>元素則吧<supported-public-render-parameter>中的參數關聯到一個擁有全局名字空間的qname上,進而它可以被portal的其他Portlet通路到。

同樣,在接收者Portlet的部署描述檔案中也平行的應該有類似定義:

<portlet-name>recentBook</portlet-name> 

chapter11.code.listing.base.RecentlyAddedBookPortlet 

<supported-public-render-parameter>  recentBookIsbn 

<identifier>  recentBookIsbn 

</identifier> 

我們可以看到,這兩個參數的qname是一緻的,是以他們是代表了同一個渲染參數。一個值改變了,則另外一個也改變。

-----

代碼中如何使用public render 參數:

雖然在Portlet 2.0中沒有定義任何設定公共渲染參數的API,但是卻提供了從PortletRequest中擷取公共渲染參數的API。

public abstract interface PortletRequest 

 public abstract Map<String, String[]> getPublicParameterMap(); 

 public abstract String getParameter(String paramString); 

 public abstract String[] getParameterValues(String paramString); 

本文轉自 charles_wang888 51CTO部落格,原文連結:http://blog.51cto.com/supercharles888/847457,如需轉載請自行聯系原作者

繼續閱讀