Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-4012

Component's onAfterRender() is called so many times as it is depth in the component tree + 1

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.5-RC7
    • Fix Version/s: 1.5.1
    • Component/s: wicket
    • Labels:
      None

      Description

      org.apache.wicket.Component.afterRender() calls org.apache.wicket.Component.onAfterRenderChildren() which for MarkupContainers calls afterRender() for its children.

      So for code like:

      WebMarkupContainer comp1 = new WebMarkupContainer("c1");
      add(comp1);

      WebMarkupContainer comp2 = new WebMarkupContainer("c2");
      comp1.add(comp2);

      WebMarkupContainer comp3 = new WebMarkupContainer("c3") {

      @Override
      protected void onAfterRender()

      { super.onAfterRender(); System.err.println("called"); }

      };
      comp2.add(comp3);

      you'll see "called" printed 4 times in a single request.

      Additionally I think onAfterRenderChildren() should be called before onAfterRender() in Component.afterRender(). The flow should be first-in last-out: onBeforeRender > onBeforeRenderChildren > onAfterRenderChildren > onAfterRender,

        Attachments

        1. WICKET-4012-afterRender.patch
          2 kB
          Martin Grigorov
        2. wicket-4012.tar.gz
          18 kB
          Martin Grigorov
        3. detachedTwice.patch
          5 kB
          Martin Grigorov

          Activity

            People

            • Assignee:
              mgrigorov Martin Grigorov
              Reporter:
              mgrigorov Martin Grigorov
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: