EL表达式中的OR条件如何?

Val*_*lva 15 jsf el jsf-2

我想在这个菜单中创建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>
Run Code Online (Sandbox Code Playgroud)

如果用户选择了"页面" team.xthml或" partnerships.xhtml页面",则"活动"值将在<li>标签中设置.

Bal*_*usC 27

这是正确的语法:

<li class="#{facesContext.viewRoot.viewId == '/company/team.xhtml' or facesContext.viewRoot.viewId == '/company/partnerships.xhtml' ? 'active' : '' }">
Run Code Online (Sandbox Code Playgroud)

为了缩短它,您可以使用#{view}而不是#{facesContext.viewRoot}:

<li class="#{view.viewId == '/company/team.xhtml' or view.viewId == '/company/partnerships.xhtml' ? 'active' : '' }">
Run Code Online (Sandbox Code Playgroud)

为了使它又短,你可以别名#{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' : '' }">
Run Code Online (Sandbox Code Playgroud)