开发者

Java Facelets and session?

开发者 https://www.devze.com 2023-01-30 01:46 出处:网络
How can I use session for facelets ? What\'s the syntax...? I would put a code like this <% String loginSession = (String)session.getAttribute(\"login\"); %>

How can I use session for facelets ?

What's the syntax...?

I would put a code like this

<% String loginSession = (String)session.getAttribute("login"); %> 
<% i开发者_开发知识库f(loginSession != null){ %> 
    Welcome <%= session.getAttribute("firstName") %> ! 
<% }else{ %> 
    Guest 
<% } %>

Thanks


#{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}" />
0

精彩评论

暂无评论...
验证码 换一张
取 消