简体   繁体   English

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

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

The following JavaScript code executed in this JSF Managed Bean 's logout method does not work, though the java code actually does. 尽管Java代码实际上可以,但是在此JSF Managed Bean的logout方法中执行的以下JavaScript代码不起作用。 So, though the log-out actually occurs, the JavaScript code (which basically click on a button) is not executed. 因此,尽管实际上发生了注销,但是未执行JavaScript代码(基本上单击了按钮)。 Any ideas of what may be happening ? 有什么想法可能发生吗? Thanks is advance ! 谢谢是前进!

@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);
        }

    }

You reload the page with window.location.reload(true); 您使用window.location.reload(true);重新加载页面window.location.reload(true); at the beginning of the script, so the browser may not have time to execute the part which goes after it, where the logout button is clicked. 在脚本的开头,因此浏览器可能没有时间执行紧随其后的部分,即单击注销按钮。

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

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