繁体   English   中英

从JSF托管Bean执行的JavaScript代码不起作用

[英]JavaScript code executed from a JSF Managed Bean not working

尽管Java代码实际上可以,但是在此JSF Managed Bean的logout方法中执行的以下JavaScript代码不起作用。 因此,尽管实际上发生了注销,但是未执行JavaScript代码(基本上单击了按钮)。 有什么想法可能发生吗? 谢谢是前进!

@SessionScoped
@ManagedBean(name = "LoginController")
public class LoginController implements Serializable {
...
public void logout() {
        try {

            RequestContext rc = RequestContext.getCurrentInstance();

            script = "$('#btnLogOut').prop('disabled', false); window.location.reload(true); $('#btnLogOut').click(); $('#btnLogOut').prop('disabled', true);";
            rc.execute(script);

            ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
            ec.invalidateSession();

        } catch (Exception e) {
            log.error("error", e);
        }

    }

您使用window.location.reload(true);重新加载页面window.location.reload(true); 在脚本的开头,因此浏览器可能没有时间执行紧随其后的部分,即单击注销按钮。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM