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();
}
Ok, so from what I understand, your problem is that even after a user logs out, the nav part of your page displays
Whereas, what you want is the same thing that happens when you get to the login the first time:
The problem, I think, is in your log out functionality. For whatever reason, even after you logout,
#{authorisation.authenticated}is returningtrue.Secondly,#{loginController.principal}still contains the value of the previously logged in user, and his/her role. Are any of these beans session scoped perhaps, or caching the value somewhere?And BalusC is right (as usual) in that you are using the word
renderedhere incorrectly. The button is the only element that is conditionallyrendered.From what I see, theWelcome, User(role), vsWelcome, Guestis based solely on the value in theloginController.If you can post some of your java code for those beans and login/logout functionality, we can try to help further