简体   繁体   中英

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. So, though the log-out actually occurs, the JavaScript code (which basically click on a button) is not executed. 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); 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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