2011-02-16 32 views
19

有沒有辦法來調用不同的後盾豆多種方法在JSF?呼叫多個後備bean的方法在同一時間

我有一個存儲用戶信息的應用程序。我有多個後臺豆,這是分解成時間表,地址,電話等。

當應用程序最初加載一切作品找到但由於我所有的意見都是類型@ViewScope日程表,地址,電話列表是即使顯示一個新的用戶維護。

我需要當用戶從他們正在查看IE瀏覽器,我需要在一個時間點來調用每個託管bean的方法目前個人導航離開手動設置日程表,地址和電話列表爲空(當上的用戶commandLink點擊)。

是否可以在一個commandLink上調用多個bean方法?

回答

2

你可以讓你的commandLink引用一個方法,它自己調用所有必要的方法。

31
<h:commandLink action="#{jsfBean.submit}" value="execute multiple methods"> 
    <f:actionListener binding="#{jsfBean1.actionListener}"/> 
    <f:actionListener binding="#{jsfBean2.actionListener}"/> 
    <f:actionListener binding="#{jsfBean3.actionListener}"/> 
</h:commandLink> 

使用上面的代碼,在豆類的方法有(「默認」)的actionListener(ActionEvent event)

簽名時,先單擊commandLink提交方法將被執行。之後,所有其他的ActionListeners將逐條執行...希望幫助;)這裏

+0

這很有幫助! :) – Nikhil 2011-04-05 15:31:24

+0

@Nikhil很高興聽到:) – Selvin 2011-04-07 05:29:57

0

的答案是接近爲我工作,但也不得不括號添加的F方法:ActionListener的:

<h:commandLink action="#{jsfBean.submit}" value="execute multiple methods"> 
    <f:actionListener binding="#{jsfBean1.actionListener()}"/> 
    <f:actionListener binding="#{jsfBean2.actionListener()}"/> 
    <f:actionListener binding="#{jsfBean3.actionListener()}"/> 
</h:commandLink>