Hi,
I'm currently using hibernate spring and JSF
1/ the first problem
In the JSF common header page I try to test if a bean is in the session scope in order to show login or logout link, and the test always fails : the logout link is always displayed.
the JSF page :
<f:subview id="header" >
<h:form id="headerForm">
<table cellspacing="0" width="100%">
<tr>
<td align="left" valign="middle">
<a href="front.jsf"><img border="0" src="images/logo1.jpg"/></a>
</td>
<td align="right" valign="middle"> <br>
<!--<a href="front.jsf" rendered="#"> Accueil<</a> -->
<c:choose>
<c:when test="${empty sessionScope.accountBean}">
<h:commandLink action="Sign on">
<h:outputText value="Sign on"/>
</h:commandLink>
</c:when>
<c:otherwise>
<h:commandLink id ="logout" action="#{accountBean.logoutAction}" >
<h:outputText value="log out"/>
</h:commandLink>
</c:otherwise>
</c:choose>
</td>
</tr>
</table>
<table cellspacing="0" width="100%">
<tr>
<td>
<hr color="#99ca3c" size="5" noShade SIZE=1>
</td>
</tr>
</table>
</h:form>
</f:subview>
The accountBean code :
public class AccountBean extends BaseBean{
//private Logger log = Log.getLog(this);
private String uid;
private String password;
private boolean loggedIn;
private AdminService adminService;
private Admin admin;
public AccountBean() {
this.logger.debug("Authentication");
this.loggedIn = false;
uid=null;
password=null;
// admin=new Admin();
}
public String loginAction() {
try {
this.logger.debug("loginAction");
admin = adminService.login(this.uid, this.password);
//this.serviceLocator.getUserService().login(this.username, this.password);
if (admin != null) {
if("".equals(admin.getUid())|| "".equals(admin.getPassword())){
this.loggedIn=false;
String msg = "Le mot de passe et l'identifiant doivent etre saisis ";
addErrorMessage(msg + ", saississez un mot de passe et un identifiant corrects");
return NavigationResults.RETRY;
}
else{
this.loggedIn = true;
HttpSession session = SessionUtil.getSession();
session.setAttribute("Admin", this.uid);
return NavigationResults.SUCCESS;
}
}
else {
this.loggedIn = false;
String msg = "Le mot de passe est incorrect ";
addErrorMessage(msg + ", saississez un mot de passe correct");
this.logger.debug(msg);
return NavigationResults.RETRY;
}
}
catch (UsernameNotExistException ue) {
String msg = "L'identifiant (login) est incorrect";
this.logger.info(msg);
addErrorMessage(msg + ", ressaysissez votre identifiant.");
return NavigationResults.RETRY;
}
catch (Exception e) {
this.logger.error("Could not log in user.", e);
addInfoMessage("Could not log in user: Internal Error");
return NavigationResults.FAILURE;
}
}
/**
* The backing bean action to logout a user.
*
* @return the navigation result
*/
public String logoutAction() {
//this.clear();
FacesContext fc = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
session.invalidate();
this.logger.debug("Logout successfully.");
return NavigationResults.MAIN;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public Admin getAdmin() {
return admin;
}
public boolean getLoggedIn() {
return loggedIn;
}
public void setLoggedIn(boolean loggedIn) {
this.loggedIn = loggedIn;
}
public void setAdminService(AdminService adminService) {
this.adminService = adminService;
}
}
the faces managed bean configuration
<managed-bean-name>accountBean</managed-bean-name>
<managed-bean-class>fr.cbmjadmin.views.bean.AccountBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>adminService</property-name>
<value>#{adminService}</value>
</managed-property>
2/ the second problem :
my application shows a list of datas.
I log on the application , i update this list outside the application ( by using sql command) , i try to list my data using the application : the application does not reflect the modifications. I logout using the log out link, then i log on and the application does not reflect the modifications.
what happens?
How could I resove these problems.
How can i logout properly?
how can i show logout link when the user is logged in? and hide the log out link when the user is logout
Thanks.