• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with Navigation in subview

 
matthew simcox
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've a banner jsf subview used on all my pages. In this banner I have a logout link that invalidates the user session then redirects to the initial login page. when the logout link was in the main page (not in a subview) it worked a treat however inside the subview the session is invalidated but no redirection occurs. The setup is as follows:

Entry page:

</ui:head>
<f:subview id="entryviewbanner">
<jsp:include page="/BannerView.jsp"/>
<jsp:include page="/EntryView.jsp"/> ***contains the link


EntryView page:

<ui:form id="form_entryview">
<h:panelGrid columns="2" id="welcomepanelgrid" style="left: 24px; top: 144px; position: absolute">
<ui:label id="welcomelabel" text="#{bundle.entryview_welcome_label}"/>
<ui:staticText id="welcometext" text="#{SessionBean.firstName} #{SessionBean.surName}"/>
<ui:label id="rolelabel" text="#{bundle.entryview_role_label}"/>
<ui:staticText id="roletext" text="#{SessionBean.role}"/>
</h:panelGrid>
<ui:hyperlink action="#{EntryView.logout_action}" id="logout" style="left: 1150px; top: 144px; position: absolute" text="#{bundle.entry_logout}"/>
</ui:form>
</f:subview>

Can anyone suggest why this wouldn't work. I really don't want to have to include the logout button in every page separately. Is there a better way of doing this?
 
matthew simcox
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to include the action code in the backing bean:

public String logout_action() {

log("Invalidating Session for user: " + getSessionBean().getProvidedUserName());

/*Invalidate the session and return user to login page*/
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpSession session = (HttpSession) externalContext.getSession(false);
session.invalidate();

return "logout";
}
 
Darryl Nortje
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howzit Matthew,

Obvious question, have you got the navigation rule setup correctly in your faces-config xml file?

cheers
Darryl
 
matthew simcox
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I believe so:

<navigation-rule>
<from-view-id>/Entry.jsp</from-view-id>
...
<navigation-case>
<from-outcome>logout</from-outcome>
<to-view-id>/login.jsp</to-view-id>
<redirect/>
</navigation-case>
...

I've had a hunt around and found this variation does work:

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpSession session = (HttpSession) externalContext.getSession(false);
session.invalidate();

Not sure what the difference is between the two though.
 
matthew simcox
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry pasted the code the wrong way around:

This doesn't work:

FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest request =
(HttpServletRequest)fc.getExternalContext().getRequest();
request.getSession().invalidate();

this does work:

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpSession session = externalContext.getSession();
session.invalidate();

The first appears to get the session off the back of the request and invalidate, the second gets the session from the external context. What is the difference here and why would it prevent naviagtion. The navigation occurs after the invalidate() is called.
 
Jerwin Louise Uy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there are some issues when redirecting using the navigation handler when the session is already invalidated.

Therefore, my suggestion is that perform a redirect when the session is already invalidated.



Regards.
 
matthew simcox
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the help. In the end I've changed it so that the navigation sends the user back to the login page and then in the constructor of the backingbean it checks to see if some login variables are null or not. if they're not null then the session gets invalidated. Any better ideas would be gratefully accepted:

public login() {



/*If user already logged in then log them out when redireted back here*/
if (getSessionBean().getRetrievedUserName() != null) {

log("About to invalidate login");

FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpSession session = (HttpSession) externalContext.getSession(false);
session.invalidate();
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic