Uploaded image for project: 'Cocoon'
  1. Cocoon
  2. COCOON-1864

RepeaterJXPathBinding - order of row is inverted

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.8, 2.1.9
    • 2.1.10, 2.2
    • Blocks: Forms
    • None
    • Urgent

    Description

      I found a bug in the forms block of Cocoon 2.1.8 / 2.1.9. I found that
      putting a min-size / initial-size attribute on a repeater element in the
      CForms model, inverts the order of rows upon binding the form. So for
      example the input document looked like:

      <document>
        <row>a</row>
        <row>b</row>
        <row>c</row>
        <row>d</row>
      </document>

      and my repeater model element's intial-size was set at 3. After
      transforming the forms template with the forms transformer, I see the
      following field instances (pseudocode):

      <field>c</field>
      <field>b</field>
      <field>a</field>
      <field>d</field>

      So what happens? The JXPathbinding for the repeater inverts the order of
      the elements with index < initial-size! I traced this bug back to the
      org.apache.cocoon.forms.binding.RepeaterJXPathBinding class, where I
      found the following code snippet in the doLoad() method:

                  while (rowPointers.hasNext()) {
                      // create a new row, take that as the frmModelSubContext
                      Repeater.RepeaterRow thisRow;
                      if (initialSize > 0) {
                          thisRow = repeater.getRow(--initialSize);
                      } else {
                          thisRow = repeater.addRow();
                      }


      I changed this into:

              int currentRow = 0;
              while (rowPointers.hasNext()) {
                  // create a new row, take that as the frmModelSubContext
                  Repeater.RepeaterRow thisRow;
                  if (currentRow < initialSize) {
                      thisRow = repeater.getRow(currentRow++);
                  } else {
                      thisRow = repeater.addRow();
                  }

      and now the binding works correctly / like I want it to work :). I must
      note that I do NOT use an identity in my repeater binding declaration.
      But I think it would be logical that leaving out the identity element
      should result in preservation of the order the elements occur in the
      input document.

      regards,
      Dennis Dam

      Attachments

        Activity

          People

            antonio Antonio Gallardo Rivera
            ddam Dennis Dam
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: