Answer the question
In order to leave comments, you need to log in
JSF: Why doesn't the rendered property work for h:outputText?
I recently started learning JEE. I use JSF2.2, EJB3, Glassfish 4.1, Hibernate 4.3. I suffered with JAAS for a long time, but in the end I was able to set it up. There is a ManagedBean that contains the current user session:
@ManagedBean
@SessionScoped
public class Auth implements Serializable {
private Users user;
@EJB private UsersFacade userService;
public Users getUser() {
if (user == null) {
Principal principal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
if (principal != null) {
user = userService.findByUsername(principal.getName());
}
}
return user;
}
public void setUser(Users user) {
this.user = user;
}
}
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
<h:head>
<title>Insurance App</title>
</h:head>
<h:body>
<h1>Welcome to Insurance Web App!</h1>
<h3>
<h:outputText rendered='#{auth.user == null}'>
<h:link outcome="login.xhtml">Login</h:link> to start work!
</h:outputText>
<h:outputText rendered='#{auth.user.username == "admin"}'>
Welcome <h:outputText value="#{auth.user.username}"/>! Here your <h:link outcome="/admin/cabinet.xhtml">Cabinet</h:link> to start work!
</h:outputText>
<h:outputText rendered='#{auth.user.username != "admin"}'>
Welcome <h:outputText value="#{auth.user.username}"/>! Here your <h:link outcome="/users/cabinet.xhtml">Cabinet</h:link> to start work!
</h:outputText>
</h3>
</h:body>
</html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question