You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Erik van Oosten <e....@grons.nl> on 2008/05/06 16:15:12 UTC

Why is it illegal to update hierarchy in onAfterRender?

Hi,

When I try to change the component hierarchy in onAfterRender I get an
exception with the text "can not change hierarchy *during* render
phase". Why is this? Isn't the render phase finished in on*After*Render?

Regards,
    Erik.

--
Erik van Oosten
http://day-to-day-stuff.blogspot.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Why is it illegal to update hierarchy in onAfterRender?

Posted by Johan Compagner <jc...@gmail.com>.
Except events back to them dont work.. (because they only lived in the
response phase of the page)

On 5/13/08, Johan Compagner <jc...@gmail.com> wrote:
> Hmm i am affraid the source for more info is the source..
>
> AutoAdd can be done in the rendering. They are only there just then.
> And they will be removed by wicket after rendering. (at least they
> should)
>
> They are or can be normal components
>
> On 5/12/08, Erik van Oosten <e....@grons.nl> wrote:
> > Johan Compagner wrote:
> > > What you can use is try to add it as auto add..
> > > So create an auto add component, we will remove those for you
> > >
> > I tried to find some more on this topic, but both google as the Wicket
> > wiki are not very informative. In the javadocs I could only find
> > MarkupContainer.html#autoAdd. Unfortunately I am not sure I understand
> > the consequences of what that method describes.
> >
> > Is there a source of more information?
> >
> > Regards,
> >     Erik.
> >
> > --
> > Erik van Oosten
> > http://day-to-day-stuff.blogspot.com/
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Why is it illegal to update hierarchy in onAfterRender?

Posted by Erik van Oosten <e....@grons.nl>.
Hi Johan,

> AutoAdd can be done in the rendering. They are only there just then.
> And they will be removed by wicket after rendering.
Thanks Johan, those 2 lines explain it for me.
Could you add them to the javadoc of MarkupContainer?

Regards,
     Erik.


Johan Compagner wrote:
> Hmm i am affraid the source for more info is the source..
>
> AutoAdd can be done in the rendering. They are only there just then.
> And they will be removed by wicket after rendering. (at least they
> should)
>
> They are or can be normal components
>
>   
--
Erik van Oosten
http://day-to-day-stuff.blogspot.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Why is it illegal to update hierarchy in onAfterRender?

Posted by Johan Compagner <jc...@gmail.com>.
Hmm i am affraid the source for more info is the source..

AutoAdd can be done in the rendering. They are only there just then.
And they will be removed by wicket after rendering. (at least they
should)

They are or can be normal components

On 5/12/08, Erik van Oosten <e....@grons.nl> wrote:
> Johan Compagner wrote:
> > What you can use is try to add it as auto add..
> > So create an auto add component, we will remove those for you
> >
> I tried to find some more on this topic, but both google as the Wicket
> wiki are not very informative. In the javadocs I could only find
> MarkupContainer.html#autoAdd. Unfortunately I am not sure I understand
> the consequences of what that method describes.
>
> Is there a source of more information?
>
> Regards,
>     Erik.
>
> --
> Erik van Oosten
> http://day-to-day-stuff.blogspot.com/
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Why is it illegal to update hierarchy in onAfterRender?

Posted by Erik van Oosten <e....@grons.nl>.
Johan Compagner wrote:
> What you can use is try to add it as auto add..
> So create an auto add component, we will remove those for you
>   
I tried to find some more on this topic, but both google as the Wicket 
wiki are not very informative. In the javadocs I could only find 
MarkupContainer.html#autoAdd. Unfortunately I am not sure I understand 
the consequences of what that method describes.

Is there a source of more information?

Regards,
    Erik.

--
Erik van Oosten
http://day-to-day-stuff.blogspot.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Why is it illegal to update hierarchy in onAfterRender?

Posted by Johan Compagner <jc...@gmail.com>.
but if you remove it
how can it be a target again for an ajax event? or that never happens?

What you can use is try to add it as auto add..
So create an auto add component, we will remove those for you

johan


On Tue, May 6, 2008 at 9:38 PM, Erik van Oosten <e....@grons.nl>
wrote:

> Hello Johan et all,
>
> Ok, I see the problem. But let me then propose a change to the exception
> text. Something like "can not change hierarchy after render phase has
> started". I'll create a Jira issue if you like.
>
> But why? Well, its one of the things I tried in a long list of attempts to
> do custom Ajax things. More experienced Wicketeers can probably point me in
> more productive directions.
>
> I have this set up where custom javascript uses the result of an Ajax
> response and places it in a modal window (or on other places in the page).
> Why? Well, our html/javascript designer refuses to use the wicket ajax
> libraries but writes everything himself. The only thing he trusts is jquery.
>
> So I worked around this by creating my own Ajax behaviors (which is pretty
> easy as you can easily get the URL that should be called from the client). I
> reused AjaxRequestTarget to generate the response. Now AjaxRequestTarget
> wants the component that is rendered to be a part of the current page. I
> therefore add the panel to be rendered to the page, even if it is not really
> used like that in the client code (as with the modal window). Therefore, at
> some moment it needs to be removed again as well.
>
> For removal I have 2 cases:
> -1- the modal window contains a form, the form might be submitted, so the
> server gets feedback.
> -2- the modal window only displays some information or the form is not
> submitted, the server gets no feedback on the close of the modal window
>
> For case -2- (in my earlier attempts) I tried to remove the component in
> onAfterRender. After realizing that this doesn't work, I did it in the
> onBeforeRender when some flag was set (accepting that it can be stored in
> the session for some time).
> But I only just realize that this case could be solved a lot better by
> using a Page instead of a Panel to deliver the content for the modal window.
>
> In case -1- however, I need to update the page that initiated the modal
> window. As we're not allowed to keep references between pages (because of
> the disk store's serialization tricks), I add the modal window panel to the
> page (with the form on it), and remove it again within the ajax-submit of
> the form. In the same onSubmit I update some components on the page,
> re-render them (again using AjaxRequestTarget) and pass them back to the
> client.
> This works, but when the form is not submitted, the modal window panel is
> never removed from the page. After a couple of such closes, the response
> time of the page easily explodes to half a minute.
>
> Ideally I would use a Page for the model window's content as well.
> However, I see no way to get a reference to the page it was opened from.
>
> Can anyone shine a little light on this? Is it possible to get that page
> reference? How does Wicket's modal window do this?
>
> Regards,
>   Erik.
>
>
>
>
> Johan Compagner wrote:
>
> > Why do you want to do that?
> > The problem is if you affect the page then the page version is
> > affected. So all what is rendered now isnt really the state wat the
> > page has.
> > Thats why you get that exception when rendering has started.
> >
> > On 5/6/08, Erik van Oosten <e....@grons.nl> wrote:
> >
> >
> > > Hi,
> > >
> > > When I try to change the component hierarchy in onAfterRender I get an
> > > exception with the text "can not change hierarchy *during* render
> > > phase". Why is this? Isn't the render phase finished in
> > > on*After*Render?
> > >
> > > Regards,
> > >    Erik.
> > >
> > > --
> > > Erik van Oosten
> > > http://day-to-day-stuff.blogspot.com/
> > >
> > >
> > >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Why is it illegal to update hierarchy in onAfterRender?

Posted by Erik van Oosten <e....@grons.nl>.
Hello Johan et all,

Ok, I see the problem. But let me then propose a change to the exception 
text. Something like "can not change hierarchy after render phase has 
started". I'll create a Jira issue if you like.

But why? Well, its one of the things I tried in a long list of attempts 
to do custom Ajax things. More experienced Wicketeers can probably point 
me in more productive directions.

I have this set up where custom javascript uses the result of an Ajax 
response and places it in a modal window (or on other places in the 
page). Why? Well, our html/javascript designer refuses to use the wicket 
ajax libraries but writes everything himself. The only thing he trusts 
is jquery.

So I worked around this by creating my own Ajax behaviors (which is 
pretty easy as you can easily get the URL that should be called from the 
client). I reused AjaxRequestTarget to generate the response. Now 
AjaxRequestTarget wants the component that is rendered to be a part of 
the current page. I therefore add the panel to be rendered to the page, 
even if it is not really used like that in the client code (as with the 
modal window). Therefore, at some moment it needs to be removed again as 
well.

For removal I have 2 cases:
-1- the modal window contains a form, the form might be submitted, so 
the server gets feedback.
-2- the modal window only displays some information or the form is not 
submitted, the server gets no feedback on the close of the modal window

For case -2- (in my earlier attempts) I tried to remove the component in 
onAfterRender. After realizing that this doesn't work, I did it in the 
onBeforeRender when some flag was set (accepting that it can be stored 
in the session for some time).
But I only just realize that this case could be solved a lot better by 
using a Page instead of a Panel to deliver the content for the modal window.

In case -1- however, I need to update the page that initiated the modal 
window. As we're not allowed to keep references between pages (because 
of the disk store's serialization tricks), I add the modal window panel 
to the page (with the form on it), and remove it again within the 
ajax-submit of the form. In the same onSubmit I update some components 
on the page, re-render them (again using AjaxRequestTarget) and pass 
them back to the client.
This works, but when the form is not submitted, the modal window panel 
is never removed from the page. After a couple of such closes, the 
response time of the page easily explodes to half a minute.

Ideally I would use a Page for the model window's content as well. 
However, I see no way to get a reference to the page it was opened from.

Can anyone shine a little light on this? Is it possible to get that page 
reference? How does Wicket's modal window do this?

Regards,
    Erik.



Johan Compagner wrote:
> Why do you want to do that?
> The problem is if you affect the page then the page version is
> affected. So all what is rendered now isnt really the state wat the
> page has.
> Thats why you get that exception when rendering has started.
>
> On 5/6/08, Erik van Oosten <e....@grons.nl> wrote:
>   
>> Hi,
>>
>> When I try to change the component hierarchy in onAfterRender I get an
>> exception with the text "can not change hierarchy *during* render
>> phase". Why is this? Isn't the render phase finished in on*After*Render?
>>
>> Regards,
>>     Erik.
>>
>> --
>> Erik van Oosten
>> http://day-to-day-stuff.blogspot.com/
>>
>>     
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Why is it illegal to update hierarchy in onAfterRender?

Posted by Johan Compagner <jc...@gmail.com>.
Why do you want to do that?
The problem is if you affect the page then the page version is
affected. So all what is rendered now isnt really the state wat the
page has.
Thats why you get that exception when rendering has started.

On 5/6/08, Erik van Oosten <e....@grons.nl> wrote:
> Hi,
>
> When I try to change the component hierarchy in onAfterRender I get an
> exception with the text "can not change hierarchy *during* render
> phase". Why is this? Isn't the render phase finished in on*After*Render?
>
> Regards,
>     Erik.
>
> --
> Erik van Oosten
> http://day-to-day-stuff.blogspot.com/
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org