ekremer
ekremer

Reputation: 311

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

    }

Upvotes: 0

Views: 252

Answers (1)

sainaen
sainaen

Reputation: 1578

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.

Upvotes: 1

Related Questions