N
N
nkalughniy2015-09-11 17:08:16
Java
nkalughniy, 2015-09-11 17:08:16

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;
    }
}

After JAAS authorization, I go to index.xhtml:
<?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>

So, the problem is: everything that has the rendered attribute is not displayed. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Axian Ltd., 2015-09-13
@AxianLTD

Apparently auth.user != null and as a result "rendered=false" ;-)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question