为什么通知栏不起作用?
我在我的应用程序中使用 primefaces 通知栏。我希望它在用户登录并重定向到名为 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):
<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秒后以淡入淡出的效果消失吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就拿
之后的脚本来说,如果你把它写在通知栏之前,它在加载时将找不到 DOM。
要使其消失,只需使用 setTimeOut( )
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()