[
https://issues.apache.org/jira/browse/WICKET-4012?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13095145#comment-13095145
]
Martin Grigorov commented on WICKET-4012:
-----------------------------------------
The same pattern is used for onDetach().
Modify the quickstart to:
WebMarkupContainer comp3 = new WebMarkupContainer("c3") {
@Override
protected void onAfterRender() {
super.onAfterRender();
System.err.println("called");
}
@Override
protected void onDetach() {
super.onDetach();
System.err.println("onDetach");
}
};
And you'll see onDetach twice per request. Again the parent component calls
onDetach for all its children and this call is recursive.
Is there a hidden purpose here ?
> Component's onAfterRender() is called so many times as it is depth in the
> component tree + 1
> --------------------------------------------------------------------------------------------
>
> Key: WICKET-4012
> URL: https://issues.apache.org/jira/browse/WICKET-4012
> Project: Wicket
> Issue Type: Bug
> Components: wicket
> Affects Versions: 1.5-RC7
> Reporter: Martin Grigorov
> Attachments: wicket-4012.tar.gz
>
>
> 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,
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira