Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditionally including a template file in ui:composition tag

Tags:

jsf

facelets

I am using facelets for templating in my jsf application. I would like to including a template file conditionally in ui:composition tag. If user is logged in the template must be "authorized.xhtml" and if the user is not logged in then the template must be "unauthorized.xhtml". Is there a way to do it? Thanks.

<ui:composition template="/templates/unauthorized.xhtml">
<ui:composition template="/templates/authorized.xhtml">

I am using JSF 1.2.

like image 356
Punter Vicky Avatar asked Dec 28 '22 09:12

Punter Vicky


1 Answers

I would try ternary operation on isAuthorized() attribute, if you have one in your log-in bean:

<ui:composition template="#{loginbean.authorized ? '/templates/authorized.xhtml' : '/templates/unauthorized.xhtml'}">

Or use two <h:panelGroup> tags with appropriate rendered values:

<h:panelGroup rendered="#{loginbean.authorized}">
    <ui:decorate template="/templates/authorized.xhtml">
</h:panelGroup>

<h:panelGroup rendered="#{not loginbean.authorized}">
    <ui:decorate template="/templates/unauthorized.xhtml">
</h:panelGroup>
like image 91
DRCB Avatar answered Jan 30 '23 12:01

DRCB