Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do an OR condition in a EL expression?

Tags:

jsf

el

jsf-2

I would like to make an OR condition in this menu :

<li class="#{facesContext.viewRoot.viewId == ('/company/team.xhtml' or '/company/partnerships.xhtml' ) ? 'active' : '' }"><a class="item" href="company/company.xhtml">Company</a>
    <ul>
        <li><a href="company/team.xhtml">Team</a></li>
        <li><a href="company/partnerships.xhtml">Partnerships</a></li>
    </ul>
</li>

That if the team.xthml or partnerships.xhtml page are selected by the user the 'active' value would be set it in the <li> tag.

like image 256
Valter Silva Avatar asked Nov 10 '11 03:11

Valter Silva


1 Answers

This is the proper syntax:

<li class="#{facesContext.viewRoot.viewId == '/company/team.xhtml' or facesContext.viewRoot.viewId == '/company/partnerships.xhtml' ? 'active' : '' }">

To make it a bit shorter, you could use #{view} instead of #{facesContext.viewRoot}:

<li class="#{view.viewId == '/company/team.xhtml' or view.viewId == '/company/partnerships.xhtml' ? 'active' : '' }">

To make it yet shorter, you could alias the #{view.viewId} with <c:set>:

<c:set var="viewId" value="#{view.viewId}" scope="request" />
...
<li class="#{viewId == '/company/team.xhtml' or viewId == '/company/partnerships.xhtml' ? 'active' : '' }">
like image 161
BalusC Avatar answered Sep 28 '22 10:09

BalusC