0

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

    }
3
  • 1
    Sounds too unclear... Maybe you can give us a little information about JS-errors from your web-console? Commented Jun 24, 2015 at 19:44
  • Hi Dmitry, thanks, but I do not have much more details because I am running JSF/PrimeFaces over JavaFX, so I do not have access to Chrome's console. I installed Firebug Lite in JavaFX, but it's not of much help either. It does not show any errors (at least I do not see them). Commented Jun 24, 2015 at 20:37
  • Most likely the javascript code doesn't work becuz you invalidate the session. Commented Jun 24, 2015 at 22:05

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi sainaen ! thanks, I will try your suggestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.