2011-04-22 33 views
1

我使用primefaces notification Bar爲我的應用程序。我希望它只出現在用戶登錄並被重定向到一個名爲main.xhml的頁面時 我正在嘗試這樣做,但我不知道爲什麼我不能讓它出現。爲什麼通知欄不起作用?

這是坐落在一個託管Bean,它確實在點擊頁面中的登錄按鈕叫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; 
      } 
     } 

這裏是用戶點擊登錄按鈕一個名爲login.xhtml

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

這裏頁面中,用戶到達時(main.xhtml)獲得loged頁:

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

在URL中,我可以看到login = 1,但是當用戶到達main.xhtml時,通知欄不會出現。

我該如何讓它出現? 另外,你知道我怎樣才能讓它消失3秒後的淡出效果?

+0

你可以看到相關的JavaScript在FF您的錯誤控制檯上的錯誤信息? – 2011-04-22 09:28:22

+0

eclipse中的控制檯沒有錯誤。而不是在瀏覽器控制檯中的錯誤。 – sfrj 2011-04-22 09:40:44

+0

不在服務器的控制檯,我在說[瀏覽器的控制檯] – 2011-04-22 09:42:09

回答

2

</p:notificationBar>之後採用腳本,因爲如果您在通知欄之前寫入DOM,它在加載時不會找到DOM。

,並使它消失,它只是叫topBar.hide()與​​

+0

我嘗試'topBar.hide()。delay(2000)'但也消失了快,爲什麼不等2秒? – sfrj 2011-04-22 10:32:05

+1

對不起,忘記延遲的東西使用這個'setTimeout(「topBar.hide()」,3000);' – 2011-04-22 10:34:54

+0

它現在完美:)謝謝! – sfrj 2011-04-22 10:36:45

相關問題