2013-05-27 33 views
1

我有一個Primefaces JSF視圖myView.xhtml,其中有一個窗體(ID爲'myformID')和數據表(ID爲'myDataTableId')。我也有一個對話框(myDialog.xhtml)。我在myView.xhtml中包含myDialog.xhtml。當我們點擊'myDialog.xhtml'中的commandButton時,它將在執行動作偵聽器中指定的方法後更新數據表。我更新數據表與更新=「:myFormId:myDataTableId」,它工作正常。重複使用Primefaces對話框

但我想在不同的視圖中使用相同的對話框。該視圖中的表單ID和數據表ID是不同的。那麼,如何重用對話框並使用不同的id更新數據表(現在我通過複製代碼並相應地更改commandButton的update屬性中的值來創建另一個對話框)?

+0

可以創建用於對話框一個JSF複合部件。如何實現複合組件的很好的例子是mkyong:http://www.mkyong.com/jsf2/composite-components-in-jsf-2-0/ – chearius

回答

1

可以傳遞參數與ui:include例如:

master.xhtml

<ui:include src="include.xhtml"> 
    <ui:param name="customId" value="4567" /> 
</ui:include> 

include.xhtml

<ui:composition> 
    <p:dialog id="#{customId}" ...> 
    </p:dialog> 
</ui:composition> 
+0

。謝謝! – user1285252