2011-11-10 25 views
12

Tôi muốn thực hiện một điều kiện OR trong menu này:Làm thế nào để điều kiện OR trong biểu thức EL?

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

Đó nếu trang team.xthml hoặc partnerships.xhtml được lựa chọn bởi người sử dụng giá trị 'hoạt động' sẽ được thiết lập nó trong thẻ <li>.

Trả lời

24

Đây là cú pháp thích hợp:

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

Để làm cho nó ngắn hơn một chút, bạn có thể sử dụng #{view} thay vì #{facesContext.viewRoot}:

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

Để làm cho nó nhưng ngắn hơn, bạn có thể bí danh #{view.viewId} với <c:set>:

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

thanks Bauke, tôi đã làm không biết tôi có thể làm ngắn hơn, cảm ơn người bạn. –

+0

Bạn được chào đón. – BalusC

Các vấn đề liên quan