我想在此菜单中设置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>标记中设置“活动”值。

最佳答案

这是正确的语法:

<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' : '' }">

10-06 02:32