2012-01-05 54 views
0

我開始使用WebSphere Portal開發基於Portlet的應用程序,現在我正在將我的開發環境切換到Liferay。 我正在使用JSR-286引入的事件系統進行Portlet間通信,試圖避免所有非標準化功能,以便爲WebSphere Portal和Liferay提供支持的環境。在Liferay中的不同頁面上使用JSR-268 IPC

如果發佈portlet和接收portlet位於同一頁面上,但我希望將這些portlet放在不同的頁面上,那麼我的事件似乎可以正常工作。在WebSphere上有一個「Wiring」配置頁面,可以將Portlet配置爲將事件發送到其他頁面上的特定Portlet,並且如果觸發此類事件,則可以選擇自動切換頁面。

如何使用Liferay做到這一點?

使用:Liferay門戶社區版6.1.0 CE(佩頓/建造6100/2011年12月15日)

回答

1

奧拉夫的答案給你一個良好的開端只是放置一個名爲portal-ext.properties文件在你的。類路徑,其內容爲portlet.event.distribution=ALL。這將確保所有關心事件的portlet都能收到它,即使它位於不同的頁面上也可以。

現在切換頁面:我建議創建一個處理事件的接口。這個接口基本上是portlet.xml文件的event-defi的表示代碼中的nition-tags。另外還有一個好處,你只需要確保你的界面和你的portlet.xml是同步的。如果接口與剩餘的源代碼不同步,那麼這通常會導致編譯時錯誤,而不是運行時錯誤(例如錯誤的事件參數類型)。

interface Events 
{ 
    public static final String EVENT_NAME_X ="eventX"; // as defined in portlet.xml 
    public static final String EVENT_NAME_Y ="eventY"; 
    public void fireEventX(ActionResponse response, ParamType param); 
    public void fireEventY(ActionResponse response, ParamType param); 
} 

然後你就可以有一個簡單的實現,激發您的活動,你可以與WebSphere使用:

public class SimpleEvents implements Events 
{ 
    @Override 
    public void fireEventX(ActionResponse response, ParamType param) 
    { 
     response.setEvent(EVENT_NAME_X, param); 
    } 

    @Override 
    public void fireEventY(ActionResponse response, ParamType param) 
    { 
     response.setEvent(EVENT_NAME_Y, param); 
    } 
} 

然後你就可以有Liferay的另一種實現方式,看起來像這樣:

public class RedirectingEvents extends SimpleEvents 
{ 
    private String eventXRedirect; 
    private String eventYRedirect; 

    @Override 
    public void fireEventX(ActionResponse response, ParamType param) 
    { 
     super.fireEventX(param); 
     if (eventXRedirect != null) 
      response.sendRedirect(eventXRedirect); 
    } 

    @Override 
    public void fireEventY(ActionResponse response, ParamType param) 
    { 
     super.fireEventY(param); 
     if (eventXRedirect != null) 
      response.sendRedirect(eventYRedirect); 
    } 
    // setters & getters 
} 

現在如果您使用的是Spring IoC(我碰巧知道您這麼做),那麼您可以在application-context.xml文件中配置實現,如下所示:

<bean class="package.RedirectingEvents" primary="true"> 
    <property name="eventXRedirect" value="/page-after-X-event" /> 
    <property name="eventYRedirect" value="/page-after-Y-event" /> 
</bean> 

這裏是你如何得到這個XML片段的「價值」 -part:

公開賽在Liferay中目標頁面到後一個事件被解僱,而beeing登錄與用戶應該被重定向適當的權限並點擊Manage->頁面頁面頂部的菜單。在那裏你可以設置一個「友好的URL」。將您在Friendly-URL字段中輸入的相同URL(不帶不可更改的前綴)複製到上面的application-context.xml片段中。

在你的類是觸發事件,那麼你可以只允許活動的界面,自動裝配,並使用它像這樣:

@Controller 
class Foobar 
{ 
    @Autowired 
    private Events portletEvents; 
    @ActionMapping 
    public void action(ActionRequest request, ActionResponse response) 
    { 
    portletEvents.fireEventX(someParam); 
    } 
    @EventMapping(Events.EVENT_NAME_Y) 
    public void handleEventRequest(EventRequest request, EventResponse response) 
    { 
    Object value = request.getEvent().getValue(); 
    log.info("got Y event! Value is: " + value); 
    } 
} 

如果您部署在WebSphere Portal應用程序,你簡單的交換XML片段上面下面:

<bean class="package.SimpleEvents" primary="true" /> 

現在你有一個解決方案,讓您在整個頁面發送JSR-286的消息,開關的同時頁面,同時仍然能夠部署你都Liferay的應用沒有WebSphere Portal代碼的任何變化(只需要修改配置)。

2

有,你可以在portal-ext.properties設置幾個屬性。對他們的評論引用(因爲他們可能說出用法比我可以做自己:

## 
## Portlet Coordination 
## 

# 
# Set this property to specify how events are distributed. If the value is 
# "layout-set", then events will be distributed to all portlets contained in 
# a layout set. If the value is "layout", then events will be distributed to 
# all portlets that are present in a layout. 
# 
portlet.event.distribution=layout 

# 
# Set this property to specify how public render parameters are distributed. 
# If the value is "layout-set", then public render parameters will be 
# distributed to all portlets contained in a layout set. This will only work 
# correctly if the property "layout.default.p_l_reset" is set to false. If 
# the value is "layout", then public render parameters will be distributed 
# to all portlets that are present in a layout. 
# 
portlet.public.render.parameter.distribution=layout 

..... 

# 
# Set the default value for the "p_l_reset" parameter. If set to true, then 
# render parameters are cleared when different pages are hit. This is not 
# the behavior promoted by the portlet specification, but is the one that 
# most end users seem to prefer. 
# 
layout.default.p_l_reset=true 

希望幫助

+0

嗯,這當然是一個改進,因爲我的事件現在被激發到目標portlet(將portal-ext.properties文件放在classpath中並指定portlet.event.distribution = ALL),但現在我仍然希望liferay切換到帶有接收portlet的頁面... – yankee 2012-01-06 22:37:26

+0

我在重定向中看到的問題是,「接收portlet」可能在語法上不正確(例如,它需要爲複數形式),因爲事件可以由許多portlet處理,它固有地模糊了切換到哪裏。但是,這是一個老問題/答案,它有一個被接受的答案,所以我假設你的問題已經解決了 - 我只是偶然發現了這個問題,並且希望澄清這些信息以便其他人找到這個問題並且想知道同樣的問題。 – 2013-02-26 08:52:13

相關問題