2011-11-10 24 views
12

我想作一個OR條件在此菜單:EL表達式中的OR條件如何?

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

,如果team.xthmlpartnerships.xhtml頁面由用戶選擇的「活躍」值將在<li>標籤來設置它。

回答

24

這是正確的語法:

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

爲了使它有點短,你可以使用#{view}代替#{facesContext.viewRoot}

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

爲了使它又短,你可以別名#{view.viewId}<c:set>

<c:set var="viewId" value="#{view.viewId}" scope="request" /> 
... 
<li class="#{viewId == '/company/team.xhtml' or viewId == '/company/partnerships.xhtml' ? 'active' : '' }"> 
+1

謝謝鮑克,我沒有不知道我可以縮短,謝謝你的朋友。 –

+0

不客氣。 – BalusC