Wicket
  1. Wicket
  2. WICKET-3229

Removing Child in IVisitor affects traversal

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.4.12
    • Fix Version/s: 1.4.15, 1.5-RC1
    • Component/s: wicket
    • Labels:
      None

      Description

      Created a Panel that provides it's own dynamically created markup stream, scans that stream for wicket:ids, and adds different components based on the id. Recently, I've been wanting to redraw this panel via AJAX, changing the markup and adding and removing child components accordingly.

      I tried to remove multiple stale components (e.g. a component that was generated from the previous markup but doesn't exist in the new markup) using an IVisitor..

      visitChildren(new IVisitor<Component>() {
      public Object component(Component component)

      { if (/* component is stale */) component.remove(); return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER; }

      The IVisitor just does a simple run through an array and removing the component adjusted the size/count of the array, messing up the traversal and preventing other components from being removed.

      Potential Solutions:
      1. Throw an exception if the hierarchy is modified in an IVisitor.
      2. Use another means of traversing the children that allows addition/removal and still ensures visiting all the children.

      1. WICKET-3229.patch
        5 kB
        Martin Grigorov

        Activity

        Hide
        Hudson added a comment -

        Integrated in Apache Wicket 1.4.x #322 (See https://hudson.apache.org/hudson/job/Apache%20Wicket%201.4.x/322/)

        Show
        Hudson added a comment - Integrated in Apache Wicket 1.4.x #322 (See https://hudson.apache.org/hudson/job/Apache%20Wicket%201.4.x/322/ )
        Hide
        Juergen Donnerstag added a comment -

        added a comment to the javadoc (1.5)

        Show
        Juergen Donnerstag added a comment - added a comment to the javadoc (1.5)
        Hide
        Igor Vaynberg added a comment -

        i think i would rather throw concurrentmodificationexception on add/remove. but honestly, this comes up so rarely that i think a javadoc note is enough.

        Show
        Igor Vaynberg added a comment - i think i would rather throw concurrentmodificationexception on add/remove. but honestly, this comes up so rarely that i think a javadoc note is enough.
        Hide
        Martin Grigorov added a comment -

        Here is an idea for Wicket 1.5.
        RemovingVisit code can be merged in Visit, but adding #remove() in IVisit doesn't look nice...

        Show
        Martin Grigorov added a comment - Here is an idea for Wicket 1.5. RemovingVisit code can be merged in Visit, but adding #remove() in IVisit doesn't look nice...

          People

          • Assignee:
            Unassigned
            Reporter:
            Jacob Brookover
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 0.5h
              0.5h
              Remaining:
              Remaining Estimate - 0.5h
              0.5h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development