2012-01-01 146 views
1

我有一個網頁p:tabView和一些p:tab裏面。在其中一個選項卡中(不是默認選項),有一個p:commandLink,單擊此按鈕時,會更新並顯示包含p:buttonp:dialog按PrimeFaces的按鈕後,防止頁面刷新

我的問題是,單擊對話框中的按鈕後,頁面刷新並再次顯示默認選項卡。相反,我希望按鈕在不刷新頁面的情況下關閉對話框。換句話說,我希望這個按鈕在服務器端觸發一個動作,在客戶端這個動作類似於對話框右上角的x關閉鏈接。

回答

1

我認爲你可以PrimeFaces v3.0.RC2的RequestContext實現它:

<p:dialog widgetVar="dialog"> 
    <p:commandButton actionListener="#{mrBean.close}" value="Close" /> 
</p:dialog> 

@ManagedBean 
@RequestScoped 
public class MrBean { 
    public void close() { 
     RequestContext context = RequestContext.getCurrentInstance(); 
     context.execute("dialog.hide();"); 
     //On primefaces >= 3.x use context.execute("PF('dialog').hide();"); 
    } 
} 
+1

這工作,但它不是最直接的解決方案這是,我從你的答案了,使用號碼:的commandButton而不是p:按鈕。這讓你可以使用actionListener =「mrBean.doSomething」type =「Button」oncomplete =「dialog.hide()」,這是足夠的,而不需要打擾RequestContext – perissf 2012-01-02 08:02:46

+0

:P哈哈斯里..我讀得太快,誤解了你,想在服務器端做到這一點 – 2012-01-02 08:26:46