MyFaces Core
  1. MyFaces Core
  2. MYFACES-3034

ui:repeat offset and size performs incorrect validation

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.3
    • Fix Version/s: 2.0.8, 2.1.2
    • Component/s: General
    • Labels:
      None
    • Environment:
      OpenJDK 1.6.0_20; Tomcat 6.0.20; Ubuntu 10.04 on kernel version 2.6.32-28-generic

      Description

      The following ui:repeat tag with those values of size and offset throw a FacesException with the message: "iteration offset cannot be greater than collection size."

      <ui:repeat var="listing" value="#

      {myListings.listings}

      " size="19" offset="20">

      It appears that the method _validateAttributes() in the UIRepeat class performs the validation incorrectly. It seems to assume that the value of size is the size of the collection, rather than the desired iteration size. Here is the relevant code from _validateAttributes():

      if ((size > -1) && (begin > size))

      { throw new FacesException ("iteration offset cannot be greater " + "than collection size"); }

      The exception is thrown in the above case because begin > size, where begin = offset = 20.

        Issue Links

          Activity

          Rey Dalisay created issue -
          Hide
          Rey Dalisay added a comment -

          Just to add ... On Mojarra 2.0.4, the size attribute is taken to mean the position of the last element to retrieve, not the number of elements to retrieve. The following tag performs on Mojarra what was originally intended from the above test case.

          <ui:repeat var="listing" value="#

          {myListings.listings}

          " size="38" offset="20">

          Show
          Rey Dalisay added a comment - Just to add ... On Mojarra 2.0.4, the size attribute is taken to mean the position of the last element to retrieve, not the number of elements to retrieve. The following tag performs on Mojarra what was originally intended from the above test case. <ui:repeat var="listing" value="# {myListings.listings} " size="38" offset="20">
          Leonardo Uribe made changes -
          Field Original Value New Value
          Link This issue is duplicated by MYFACES-3183 [ MYFACES-3183 ]
          Leonardo Uribe made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Assignee Leonardo Uribe [ lu4242 ]
          Fix Version/s 2.0.8 [ 12316514 ]
          Fix Version/s 2.1.2 [ 12316512 ]
          Resolution Fixed [ 1 ]
          Hide
          Leonardo Uribe added a comment -

          From users list:

          Please help to publish the latest MyFaces 2.0.8-SNAPSHOT

          OK, I was thinking that an old MyFaces snapshot is used as I got a failure
          in my sample for some changes are done to UIRepeat tag in
          MYFACES-3034<https://issues.apache.org/jira/browse/MYFACES-3034> .
          After some investigation later, it seems that the changes brought a problem.
          If repeat tag is used as :
          <ui:repeat var="listing" value="#

          {myListings.listings}

          " offset="20">
          An exception is always thrown on line 457,
          --->
          if (size == -1)

          { size = end; <-- Should it be size = end - offset ? }

          if (end >= 0) {
          if (size < 0)

          { throw new FacesException ("iteration size cannot be less " + "than zero"); }

          else if ((begin + size) > end) {
          throw new FacesException ("iteration size cannot be greater
          " + <--- Exception is always thrown
          "than collection size");

          Show
          Leonardo Uribe added a comment - From users list: Please help to publish the latest MyFaces 2.0.8-SNAPSHOT OK, I was thinking that an old MyFaces snapshot is used as I got a failure in my sample for some changes are done to UIRepeat tag in MYFACES-3034 < https://issues.apache.org/jira/browse/MYFACES-3034 > . After some investigation later, it seems that the changes brought a problem. If repeat tag is used as : <ui:repeat var="listing" value="# {myListings.listings} " offset="20"> An exception is always thrown on line 457, ---> if (size == -1) { size = end; <-- Should it be size = end - offset ? } if (end >= 0) { if (size < 0) { throw new FacesException ("iteration size cannot be less " + "than zero"); } else if ((begin + size) > end) { throw new FacesException ("iteration size cannot be greater " + <--- Exception is always thrown "than collection size");
          Leonardo Uribe made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Leonardo Uribe made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Leonardo Uribe made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Hide
          Thomas Timbul added a comment -

          I know this is old, but in the original facelets (JSF 1.2) it used to be possible to use the "size" attribute to restrict the iteration size to a "maximum" value. Take this scenario:

          Collection size: 2
          ui:repeat "size": 3

          Without "offset" specified, a maximum of 3 items would be rendered, in this case 2.
          After this "fix" (yea, I finally got to upgrade something after nearly 3 years!), this no longer works and requires some fairly ugly workarounds, such as adding a custom function:

          <ui:repeat value="#{coll}" size="#{c:max(coll.size(), 3)}">
          

          As to why the spec would suggest that an exception be thrown when it would be dead simple to make the implementation tolerant is beyond me. But the original facelets WAS tolerant of setting a size larger than the actual collection. After all, why should the view know what the size of a collection is at runtime? The view should only be concerned with what the user interface will tolerate as a maximum...

          Show
          Thomas Timbul added a comment - I know this is old, but in the original facelets (JSF 1.2) it used to be possible to use the "size" attribute to restrict the iteration size to a "maximum" value. Take this scenario: Collection size: 2 ui:repeat "size": 3 Without "offset" specified, a maximum of 3 items would be rendered, in this case 2. After this "fix" (yea, I finally got to upgrade something after nearly 3 years!), this no longer works and requires some fairly ugly workarounds, such as adding a custom function: <ui:repeat value= "#{coll}" size= "#{c:max(coll.size(), 3)}" > As to why the spec would suggest that an exception be thrown when it would be dead simple to make the implementation tolerant is beyond me. But the original facelets WAS tolerant of setting a size larger than the actual collection. After all, why should the view know what the size of a collection is at runtime? The view should only be concerned with what the user interface will tolerate as a maximum...
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          134d 8h 17m 1 Leonardo Uribe 22/Jun/11 17:19
          Resolved Resolved Reopened Reopened
          6d 12h 53m 1 Leonardo Uribe 29/Jun/11 06:13
          Reopened Reopened Resolved Resolved
          16h 16m 1 Leonardo Uribe 29/Jun/11 22:29
          Resolved Resolved Closed Closed
          54d 5h 6m 1 Leonardo Uribe 23/Aug/11 03:36

            People

            • Assignee:
              Leonardo Uribe
              Reporter:
              Rey Dalisay
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development