0
votes

I am wanna to have notification bar in my jsf page. When I use this sample code it works

    <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"/>

but when I use this code it doesn't work

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

Why and what does this PF do ? My final approach is to have auto hide notification panel, but when I used code like this

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

It shows this error :

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

and by this code

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

it shows

Uncaught ReferenceError: notifBaris not defined

Could anyone help me please ..

1

1 Answers

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

notifBar is equal to widgetVar="notifBar" which means its a client side component and your server doesn't know about notifbar, to show it, you have to do it like: PF('client_Wiget_War').show;

By Doc: 'widgetVar is the name of the client side variable' here

WRT hiding notification bar

Uncaught ReferenceError: notifBar is not defined

This occurrs because notifBar is client side component For now I am trying to replicate your setTimeout scenario but i am failed.