2015-05-09 208 views
1

我不知道我應該如何描述這個問題。 我目前正在學習JSF,今天試圖實現類似ajax重載表與分頁。JSF無效行爲與jstl foreach與不同的jsf版本

這是我在JSF代碼:

<c:forEach var="pageNo" begin="0" end="${adapter.pagesNumber}"> 
<c:choose> 
    <c:when test="#{adapter.currentPage == pageNo}"> 
     <li class="active"><h:commandLink value="#{pageNo+1}" disabled="true" /></li> 
    </c:when> 
    <c:otherwise> 
     <li><h:commandLink value="#{pageNo+1}" action="#{adapter.setCurrentPage(pageNo)}"> 
       <f:ajax render=":#{cc.attrs.tableId} @form" /> 
      </h:commandLink></li> 
    </c:otherwise> 
</c:choose> 

,我使用JSF來自:

<dependency> 
    <groupId>org.glassfish</groupId> 
    <artifactId>javax.faces</artifactId> 
</dependency> 

我的目的是有頁碼按鈕,與當前活動頁面按鈕突出顯示並禁用(不重複加載相同的頁面)。

現在,第一張截圖顯示了任何行動之前,我的觀點:(第一頁): enter image description here

可以說,我點擊頁碼6,

而現在,當我使用JSF與

版本
 <version>2.2.4</version> 

我得到了預期的結果: enter image description here

但是,當I S女巫的版本高於例如

 <version>2.2.5</version> // tested up to 2.2.11 

我得到這樣的: enter image description here

我點擊沒有第9頁後,我得到了另一個「分頁」序列:

1 2 3 4 5 7 8 9 6 10 11 

但當前頁面中左下角說這是第9頁。表格內容也是有效的。

有沒有人曾經遇到像這樣的情況或我做錯了什麼,如果相同的代碼與不同的JSF版本完全不同?什麼可能是這種奇怪行爲的原因?

+0

請在此處發佈您的mcve(請參閱[ask]),而不是pastebin – Kukeltje

+0

我後來發現,使用JSTL和JSF導致出現意外行爲(如此)時可能存在不一致,但它仍然不能解釋爲什麼與2.2.4版本的工作(或至少它試圖工作)預期的方式,並與> 2.2.4不。 – Invader92

+0

你發佈的內容不是mcve。這是一個片段。是的,這很奇怪,但可能是因爲其他改進,有些工作(但沒有專門設計的工作)在其他改進時停止工作。你有沒有嘗試'ui:repeat' btw? – Kukeltje

回答

0

解決方案,其工作對我來說,問題是去除

<c:choose> 
    <c:when> 
    .... 
</c:choose> 

標籤,只是把的c:whenc:otherwise內容與添加其中預計布爾表達式,如屬性rendered

<c:when test="#{page.currentPageNumber == pageNumer}"> 
    <h:commandLink ... /> 
</c:when> 

替換:

<h:commandLink rendered="#{page.currentPageNumber == pageNumer" ... /> 

的根本原因是我想JSTL和JSF的執行順序,指出here