1

I am not really sure how should I describe the problem. I am currently learning JSF, and today tried to implement something like ajax reloaded table with pagination.

Here is my code in 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>

And I am using JSF from:

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

My intention was to have buttons with page numbers, with currently active page button highlighted and disabled (no same page reloading).

Now, first screenshot shows my view before any action: (first page): enter image description here

Lets say I clicked on page number 6,

And now, when I use JSF with version

     <version>2.2.4</version>

I got expected result: enter image description here

But when I switch on versions above e.g.

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

I'm getting something like this: enter image description here

After I've clicked on page no 9 i got another "pagination" sequence:

1 2 3 4 5 7 8 9 6 10 11

but the current page in left bottom corner says it's 9th page. Table content is valid too.

Does anyone have ever faced with situaton like this or what am I doing wrong, if the same code works totally different with different JSF versions? What can be a reason of such weird behavior?

Invader
  • 105
  • 1
  • 12
  • Please post your mcve (see [ask]) here instead of on pastebin – Kukeltje May 09 '15 at 08:41
  • I've found later that there might be inconsistence while using JSTL with JSF resulting with unexpected behavior such as this, yet it still does not really explain why with version 2.2.4 it works (or at least it tries to work) expected way, and with > 2.2.4 not. – Invader May 09 '15 at 10:33
  • What you post is not an mcve. It is a snippet. And yes it is strange, but it might be because of other improvements that something that worked (but was not specifically designed to work) stops working when other improvements were made. Did you try `ui:repeat` btw? – Kukeltje May 09 '15 at 10:44
  • With 'other improvements' I mean in jsf in general – Kukeltje May 09 '15 at 11:41
  • I understand. Actually, I found my solution by [that answer](http://stackoverflow.com/a/7437930/4115083). Now I was just curious, why it worked before switching on newer version. Thank you. – Invader May 09 '15 at 11:50
  • Wait :) Although having this in a composite component is a bit awkward (better use a tagfile), it should work nonetheless. I myself suspect the `` from being the cause (as potential unexpected side effect of [this 2.2.5 fix](https://java.net/jira/browse/JAVASERVERFACES-3084)). What if you prepare an integer array and just use `` instead? In any case, what exactly have you replaced based on that answer? Only the `` or also the ``? – BalusC May 09 '15 at 13:36
  • As for the tagfile, I'm still learning and didn't get there yet. Passing indexes or array has the same result. Solution to this problem (not sure if proper) was to remove c:choose, and add to html tags `rendered` attirbute with proper expression. – Invader May 09 '15 at 15:37
  • @invader92: can you pleasecreate your own answer with what you did...? – Kukeltje May 10 '15 at 07:14

1 Answers1

0

Solution for the problem which worked for me was remove the

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

tags, and just put the content of c:when and c:otherwise with adding an attribute rendered which expects boolean expression eg.

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

replaced with:

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

The root cause is I guess execution order of JSTL and JSF, pointed here.

Community
  • 1
  • 1
Invader
  • 105
  • 1
  • 12