Search code examples
javasessionjsffacelets

Java Facelets and session?


How can I use session for facelets ?

What's the syntax...?

I would put a code like this

<% String loginSession = (String)session.getAttribute("login"); %> 
<% if(loginSession != null){ %> 
    Welcome <%= session.getAttribute("firstName") %> ! 
<% }else{ %> 
    Guest 
<% } %>

Thanks


Solution

  • #{sessionScope.login}
    

    You can't have if-s in JSF (you can with JSTL, but it has complications). Instead you can choose to render or not a component:

    <h:outputText value="Guest" rendered="#{sessionScope.login != null}" />