mercredi 20 mai 2015

Login Command Button doesnt work after closing page and open it in new tab

I have simple login page :

<h:form>
 <p:inputText id="Login" value="#{loginBean.login}" />
 <p:password id="pass" value="#{loginBean.pass}" />
 <p:commandButton value="Login" actionListener="#{loginBean.makeLogin()}" ajax="true" update= @this" />
</h:form>

LoginBean is @Named Bean with org.omnifaces.cdi.ViewScoped Scope. It has getters and setters, and makeLogin method.

Application works fine mostly, i can log in, log out and repeat it. However when i log in, then log out and close tab with xhtml Page than open it again in new tab problems happends.

First i created method with @PostConstruct annotation to see if bean is initializing. It is - i can see logs. Bu then if i click on Login button nothing happends. I don't see logs from makeLogin (first thing i do in that method is log it). Only thing i can do is clean cookies -> refresh page and than all works fine. Refreshing page without clearing cookies doesn't work.

My logout method has that lines:

FacesContext.getCurrentInstance().getExternalContext().getSessionMap().clear();
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();

And login:

FacesContext.getCurrentInstance().getExternalContext()
                        .getSessionMap().put("username", login);

Session checking on pages is i think done throught

public class AuthorizationListener implements PhaseListener {

private static final long serialVersionUID = 1L;

public void afterPhase(PhaseEvent event) {
    FacesContext facesContext = event.getFacesContext();    
    String currentPage = facesContext.getViewRoot().getViewId();

    boolean isLoginPage = (currentPage.lastIndexOf("index.xhtml") > -1);

    HttpSession session = (HttpSession) facesContext.getExternalContext()
            .getSession(false);

    if (session == null) {
        NavigationHandler nh = facesContext.getApplication()
                .getNavigationHandler();
        nh.handleNavigation(facesContext, null, "index");

    }

    else {
        Object currentUser = session.getAttribute("username");
        if (!isLoginPage && (currentUser == null || currentUser == "")) {
            NavigationHandler nh = facesContext.getApplication()
                    .getNavigationHandler();
            nh.handleNavigation(facesContext, null, "index");
        }
        if(isLoginPage && currentUser != null && currentUser != ""){
            NavigationHandler nh = facesContext.getApplication()
                    .getNavigationHandler();
            nh.handleNavigation(facesContext, null, "panel");

        }
    }
}

public void beforePhase(PhaseEvent event) {

}

public PhaseId getPhaseId() {
    return PhaseId.RESTORE_VIEW;
}
}

In web.xml i have

  <session-config>
<session-timeout>5760</session-timeout>
 </session-config>

I'm running app on jboss eap 6.3 with JSF 2.1

I was trying to change commandButton, and methods it fires but couldn't find workaround.

Aucun commentaire:

Enregistrer un commentaire