2015-02-24 87 views
0

我想在我的jsf頁面中有通知欄。當我使用此示例代碼它的工作原理jsf2 primefaces通知欄

<p:notificationBar position="top" effect="slide" styleClass="top" widgetVar="notifBar"> 
     <h:outputText value="Hi ..." style="font-size:36px;" /> 
    </p:notificationBar> 

    <p:commandButton value="Show2" onclick="PF('notifBar').show();" type="button"/> 

但是當我使用此代碼它不工作

<p:commandButton value="Show1" onclick="notifBar.show()" type="button"/> 

爲什麼和是什麼PF呢? 我的最終方法是讓自動隱藏通知面板,但是當我用這樣的

<p:commandButton value="Show2" onclick="PF('notifBar').show();setTimeout(PF('notifBar').hide, 3000)" type="button"/> 

代碼它顯示了這個錯誤:

Uncaught TypeError: Cannot read property 'effect' of undefined PrimeFaces.widget.NotificationBar.PrimeFaces.widget.BaseWidget.extend.hide

,並通過這個代碼

<p:commandButton value="Show2" onclick="PF('notifBar').show();setTimeout(notifBar.hide, 3000)" type="button"/> 

它顯示

Uncaught ReferenceError: notifBaris not defined

誰能幫我請..

回答

0
<p:commandButton value="Show1" onclick="notifBar.show()" type="button"/> 

notifBar等於widgetVar="notifBar"這意味着它的客戶端組件和服務器不知道notifbar,展現它,你必須做到這一點,如:PF('client_Wiget_War').show;

通過文檔: 'widgetVar是客戶端變量的名稱' here

WRT隱藏通知欄

Uncaught ReferenceError: notifBar is not defined

這是因爲notifBar是客戶端組件 現在我試圖複製您的setTimeout方案,但我失敗了。