Hey folks,
I have a problem with my facelets:
I constricted a nav part that displays login information for about curren user and a logout button. Login works properly. But after a user logs out, the nav part of my page displays
Welcome, User (role) [Logout_Button]
Whereas, what I want is the same thing that happens when you get to the login the first time:
Welcome, Guest
(Thank you Java drinker for those easy words :-))
Here you can see part of my template:
<div id="metaContainer">
<ui:include src="/metaMenu.xhtml" />
</div>
That's my nav part with login info (called metaMenu.xhtml):
<ui:composition xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
<div id="login_info">
<h:outputLabel value="Willkommen, "/>
<h:outputLabel class="principal" value="#{metaNavData.principal}"/>
<h:outputLabel value="#{metaNavData.role}"/>
</div>
<div id="meta_nav">
<h:form name="loginform" rendered="#{authorisation.authenticated}">
<h:commandLink action="#{loginController.logout}" rendered="#{authorisation.authenticated}">
Logout</h:commandLink>
</h:form>
</div>
</ui:composition>
As BalusC and Java Drinker assumed it could be a java logic problem. I first need to say, that I use Apache Shiro for security issues. So here is the relevant Java code:
my loginController that contains the logout method:
@ManagedBean
@SessionScoped //Mistake!!! That should be RequestScoped, see below
public class LoginController {
private Subject currentUser; // import org.apache.shiro.subject.*;
public LoginController() {
currentUser = SecurityUtils.getSubject();
}
public String logout() {
if (currentUser.isAuthenticated()) {
currentUser.logout();
}
return "welcome.xhtml";
}
And her you can see my backed bean 'authorisation', which is supposed to provide information that can be used to hide comonents like the loginbutton:
@ManagedBean
@RequestScoped
public class Authorisation {
private Subject currentUser;
public Authorisation(){
currentUser = SecurityUtils.getSubject();
}
public boolean getAuthenticated(){
return currentUser.isAuthenticated();
}