DisplayTag
  1. DisplayTag
  2. DISPL-334

display:table pagesize="xx" attrinute fail with multiple tables in same JSP

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.1
    • Fix Version/s: 1.1.1
    • Component/s: Tag Library
    • Labels:
      None
    • Application server:
      JBoss 4.0.3SP1

      Description

      _display:table name="requestScope.purchaseItems_list" class="tab" pagesize="6"_

      I have 2 tables underneath each other in a data mining-like web application.
      The tables resides in different JSP fragment files that are included from a main JSP page.

      If the bottom table are sent an empty list, displaytag crashes (but only if the pagesize attribute exist in the JSP).
       - if the bottom list contains data, everything is OK
       - if the bottom list JSP doesn't use the pagesize="x" attribute, everything is OK


      Example (Bottom list is empty, and pagesize="6"):
      -results in this stack trace:

      15:16:59,075 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
      java.lang.IndexOutOfBoundsException: fromIndex = -6
      at java.util.SubList.<init>(AbstractList.java:703)
      at java.util.RandomAccessSubList.<init>(AbstractList.java:861)
      at java.util.AbstractList.subList(AbstractList.java:570)
      at org.displaytag.pagination.SmartListHelper.getListForPage(SmartListHelper.java:219)
      at org.displaytag.pagination.SmartListHelper.getListForCurrentPage(SmartListHelper.java:200)
      at org.displaytag.tags.TableTag.setupViewableData(TableTag.java:1525)
      at org.displaytag.tags.TableTag.doEndTag(TableTag.java:1198)
      at org.apache.jsp.list.PurchaseItems_jsp._jspService(org.apache.jsp.list.PurchaseItems_jsp:696)


      From debugging SmartListHelper:

      line 166:
        return (pageNumber - 1) * this.pageSize;

      line 217-219:
        int firstIndex = getFirstIndexForPage(pageNumber);
        int lastIndex = getLastIndexForPage(pageNumber);
        return this.fullList.subList(firstIndex, lastIndex + 1);


      When line 217 call line 166, and there are no pages (pageNumber=0), the returned index is (-1 * 'the defined pagesize from JSP'),
      which results in the stack trace above

        Activity

        Hide
        Knut Erik Ballestad added a comment -
        Hi

        Here's my patch for this issue.
        The patch is tested (but not intensively yet...), and is a patch for version 1.1 of displaytag


        regards


        Knut Erik Ballestad
        Show
        Knut Erik Ballestad added a comment - Hi Here's my patch for this issue. The patch is tested (but not intensively yet...), and is a patch for version 1.1 of displaytag regards Knut Erik Ballestad
        Hide
        Bryan J. Nelson added a comment -
        Howdy,

        I've implemented this patch into a version of an application I'm working on and so far it seems to work just fine.

        Many thanks!

        bryan j nelson
        Show
        Bryan J. Nelson added a comment - Howdy, I've implemented this patch into a version of an application I'm working on and so far it seems to work just fine. Many thanks! bryan j nelson
        Hide
        Barry Lagerweij added a comment -
        I tried the patch as well, but it screwed up the results of page 2 and further: Page 2 only displayed results that used a 'property=' for the column, and ignored the contents of the tag 'display:column'. Furthermore, for the results it *DID* display, it always showed the results of page 1 (!). So although the patched looked promising, the end result was not what I expected.

        I did however find a different solution: The two <display:table> elements were using the same value for the 'id' attribute, which was causing the mixup of the two instances. Changing the id of the second <displaytag:table> solved my problems.
        Show
        Barry Lagerweij added a comment - I tried the patch as well, but it screwed up the results of page 2 and further: Page 2 only displayed results that used a 'property=' for the column, and ignored the contents of the tag 'display:column'. Furthermore, for the results it *DID* display, it always showed the results of page 1 (!). So although the patched looked promising, the end result was not what I expected. I did however find a different solution: The two <display:table> elements were using the same value for the 'id' attribute, which was causing the mixup of the two instances. Changing the id of the second <displaytag:table> solved my problems.
        Hide
        fabrizio giustina added a comment -
        Unable to reproduce the error on the current trunk, I've added a testcase (DISPL-334.jsp) and tweaked SmartListHelper so that is should never return values > 0.
        Show
        fabrizio giustina added a comment - Unable to reproduce the error on the current trunk, I've added a testcase ( DISPL-334 .jsp) and tweaked SmartListHelper so that is should never return values > 0.

          People

          • Reporter:
            Knut Erik Ballestad
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: