我想要做的只是一个简单的注销功能.主页面将调用模板页面;由标题和内容组成.标题包含注销按钮.页面中将有两个表单,一个在标题中(注销按钮),一个在内容中(几个按钮,链接等).
我的问题是首次点击注销链接时页面刷新,只在第二次点击后才进行.当我在内容表单中包含primefaces或ajax代码时,问题就开始出现了.当我删除该特定代码时,注销按预期工作.
主模板templateUser.xhtml中的注销表单:
<h:form id="logout"> <h:commandLink action="#{tenantController.customlogout(e)}" id="logoutBtn" immediate="true" value="logout" /> </h:form>
支持bean:
public String customlogout(ActionEvent e) { return "login.xhtml"; }
仅供参考:customlogout方法也包含会话销毁,但我只是将页面重定向放在这里.
在模板客户端中,模板指定为:
<ui:composition template="/templateUser.xhtml">
至于JSF库,目前使用jsf 2.0
我试过的解决方案:
> immediate =“true”
>为表单和commandLink(模板表单和内容表单)输入id
>使用primefaces(< p:commandLink> ajax false ==>这返回上一页;后备bean中的方法没有运行.
> commandButton/commandLink/ajax action/listener method not invoked or input value not updated
> How can I prevent page refresh on click of <h:commandLInk>
> JSF PrimeFaces p:commandLink won’t redirect to new page?
解决方法
The problem starts to appear when I include primefaces or ajax code inside the content form. When I remove that particular code,the logout works as intended.
您的问题是由commandButton/commandLink/ajax action/listener method not invoked or input value not updated中描述的第7点引起的.当您使用< f:ajax>触发ajax请求时并执行一个也涵盖所有其他表单的更新,然后所有其他表单将失去其视图状态.这导致第一次提交将始终“不执行任何操作”,但下一次提交将起作用,这与您的问题症状完全匹配.
您可以通过以下方式之一解决此问题:
>在< f:ajax render>中明确指定所有其他表单的客户端ID.您可以指定多个客户端ID空间分隔.例如.
<f:ajax ... render="someComponent otherComponent :loginForm" />
>使用本答案中建议的基于JavaScript的修补程序:h:commandButton/h:commandLink does not work on first click,works only on second click.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。