我想在此菜单中创建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.xthml
或partnerships.xhtml
页面,则会在<li>
标记中设置“有效”值。
答案 0 :(得分:26)
这是正确的语法:
<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' : '' }">
为了缩短它,您可以使用<c:set>
将#{view.viewId}
设为别名:
<c:set var="viewId" value="#{view.viewId}" scope="request" />
...
<li class="#{viewId == '/company/team.xhtml' or viewId == '/company/partnerships.xhtml' ? 'active' : '' }">