开发者

why notification bar does not work?

开发者 https://www.devze.com 2023-02-28 15:26 出处:网络
I use primefaces notification Bar for my app. I want it to appear just when an user logs in and gets redirected to a page called main.xhml

I use primefaces notification Bar for my app. I want it to appear just when an user logs in and gets redirected to a page called main.xhml I am trying to do it but i don't know why i cant make it appear.

This is a method that is located in a managed bean that does the redirect when clicked the login button at a page called login.xhtml:

@ManagedBean
@RequestScoped
public class SecurityController {

    @EJB
    private IAuthentificationEJB authentificationEJB;

    public String logIn() {
            if (authentificationEJB.saveUserState(email, password)) {
                // Pass a parameter in ussing the URL.(The notification bar will
                // read this parameter)
                return "main.xhtml?faces-redirect=true&login=1";
            } else {
                return null;
            }
        }

Here is the button that the users click to login at a page called login.xhtml

<h:commandButton value="Login" action="#{securityController.logIn()}"/>

Here is the page where the users arrive when get loged in(main.xhtml):

<ui:composition template="WEB-INF/templates/BasicTemplate.xhtml">

    <ui:define name="mainForm">

        <h2>The main page</h2>
        <!-- Why this dont work? -->
        <script type="text/javascript">
          jQuery(function() {
          topBar.show()
           });
         </script>
        <!-- It is 开发者_运维百科possible to change font -->
        <p:notificationBar id="notbar" position="top" widgetVar="topBar" styleClass="top" rendered="#{param.login == '1'}">
            <h:outputText value="Welcome, you are now logged in!"
                style="color:#FFCC00;font-size:36px;" />
        </p:notificationBar>

    </ui:define>
   </ui:composition>

In the URL i can see login=1, but when the user arrives to main.xhtml the notification bar does not appear.

How can i make it appear? Also, do you know how can i make it disappear with a fade effect after 3 seconds?


Take the script after </p:notificationBar> as It won't find the DOM when it is loading if you write it before the notification bar.

and to make it disappear it just call topBar.hide() with setTimeOut()

0

精彩评论

暂无评论...
验证码 换一张
取 消