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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.5-RC7
    • 1.5.1
    • wicket
    • 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 Tzvetanov Grigorov
        2. wicket-4012.tar.gz
          18 kB
          Martin Tzvetanov Grigorov
        3. detachedTwice.patch
          5 kB
          Martin Tzvetanov Grigorov

        Activity

          People

            mgrigorov Martin Tzvetanov Grigorov
            mgrigorov Martin Tzvetanov Grigorov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: