You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Korbinian Bachl <ko...@whiskyworld.de> on 2018/05/08 11:48:58 UTC

wicket component lifecycle after form submit

Hi,

from https://ci.apache.org/projects/wicket/guide/8.x/single.html#_lifecycle_stages_of_a_component and https://ci.apache.org/projects/wicket/guide/6.x/guide/componentLifecycle.html I see how the lifecycle of a wicket component is intended to be.

But how does it go for the lifecycle of a component on a page where the page gets submitted by a form in another component?

I know that the page tree wont get recreated completely after the onSubmit, but I wonder if there is any method that is guaranteed to be called on each re-render phase as I somehow struggle with parallel CDI work done in a @RequestScoped bean 
(this is re-created completely when the submit is called as it is a new http request) 
and some things in onBeforeRender wont even get called - or can it be that this is because the "hasBeenRendered" is true for rerenders by form submits?

Sorry if the question is dumb but I somehow locked myself in by doing too much in different onBeforeRender methods all over the place..  (that is also mainly because most of that code stems from wicket 1.3/1.4 era);

Is there a method that gets executed every rerender after the page has been constructed - similar to onConfigure ?

Best,

KB



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


Re: wicket component lifecycle after form submit

Posted by Martin Grigorov <mg...@apache.org>.
On Tue, May 8, 2018 at 5:11 PM, Korbinian Bachl <
korbinian.bachl@whiskyworld.de> wrote:

>
>
> ----- Ursprüngliche Mail -----
> >
> >> But how does it go for the lifecycle of a component on a page where the
> >> page gets submitted by a form in another component?
> >>
> >
> > I do not understand this sentence
>
>
> It may sound a bit awkward but the situation is like this:
>
> Page with componentes A, B, C, D on it
> Component A is just an resolver that fills a request scoped CDI with
> decoded data for components B,C,D in its constructor
> Component B,C,D now reacts onto these data from Component A in the
> onBeforeRender method
>
> all is fine if its not rerendered like it was used some years now (code
> stems from looong time ago :/ )
>
> now I introduced an form into component D and there the mess began as A's
> construtor didnt get called again as its page was already rendered...
>
> this was all made before wicket had the current lifecycle as well as the
> methods that get invoked we have today in wicket 7 and 8;
>

The Request*Cycle* has been re-worked in Wicket 1.5.
Some new methods have been added to the Component lifecycle - onInitialize
and onConfigure.
But Component's constructor has been called just *once* (for a stateful
page!) since I know Wicket (around early days of Wicket 1.3).

If the page is *stateless* then the page and its complete component tree
will be re-created, i.e. their constructors will be called on each request.


>
>
> >
> >>
> >
> > onConfigure() and onDetach() are called at every request
> > if the component is visible then onBeforeRender, onRender() and
> > onAfterRender() will be called too
>
> Ah ok,
>
> So is it correct if I assume that onConfigure gets called in the same
> order as the components get added to the page and in that order on each
> re-render?
>
> What would be the best way in 2018 to have decoupled components that share
> logic?
>

The same as 10 years ago, I'd say.
With Java 8 you can have interfaces with default impls but all other ways
for sharing logic between several classes are pretty old.
If you use more modern JVM languages then the options are bigger.
If you ask for Wicket specific ways again it is the same as before - you
can use Behavior to share common logic between Components.


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

Re: wicket component lifecycle after form submit

Posted by Korbinian Bachl <ko...@whiskyworld.de>.

----- Ursprüngliche Mail -----
> 
>> But how does it go for the lifecycle of a component on a page where the
>> page gets submitted by a form in another component?
>>
> 
> I do not understand this sentence


It may sound a bit awkward but the situation is like this:

Page with componentes A, B, C, D on it
Component A is just an resolver that fills a request scoped CDI with decoded data for components B,C,D in its constructor
Component B,C,D now reacts onto these data from Component A in the onBeforeRender method

all is fine if its not rerendered like it was used some years now (code stems from looong time ago :/ )

now I introduced an form into component D and there the mess began as A's construtor didnt get called again as its page was already rendered... 

this was all made before wicket had the current lifecycle as well as the methods that get invoked we have today in wicket 7 and 8;


> 
>>
> 
> onConfigure() and onDetach() are called at every request
> if the component is visible then onBeforeRender, onRender() and
> onAfterRender() will be called too

Ah ok,

So is it correct if I assume that onConfigure gets called in the same order as the components get added to the page and in that order on each re-render?

What would be the best way in 2018 to have decoupled components that share logic?


Best,

KB

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


Re: wicket component lifecycle after form submit

Posted by Martin Grigorov <mg...@apache.org>.
On Tue, May 8, 2018 at 2:48 PM, Korbinian Bachl <
korbinian.bachl@whiskyworld.de> wrote:

> Hi,
>
> from https://ci.apache.org/projects/wicket/guide/8.x/
> single.html#_lifecycle_stages_of_a_component and https://ci.apache.org/
> projects/wicket/guide/6.x/guide/componentLifecycle.html I see how the
> lifecycle of a wicket component is intended to be.
>
> But how does it go for the lifecycle of a component on a page where the
> page gets submitted by a form in another component?
>

I do not understand this sentence


>
> I know that the page tree wont get recreated completely after the
> onSubmit, but I wonder if there is any method that is guaranteed to be
> called on each re-render phase as I somehow struggle with parallel CDI work
> done in a @RequestScoped bean
> (this is re-created completely when the submit is called as it is a new
> http request)
> and some things in onBeforeRender wont even get called - or can it be that
> this is because the "hasBeenRendered" is true for rerenders by form submits?
>
> Sorry if the question is dumb but I somehow locked myself in by doing too
> much in different onBeforeRender methods all over the place..  (that is
> also mainly because most of that code stems from wicket 1.3/1.4 era);
>
> Is there a method that gets executed every rerender after the page has
> been constructed - similar to onConfigure ?
>

onConfigure() and onDetach() are called at every request
if the component is visible then onBeforeRender, onRender() and
onAfterRender() will be called too


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