Re: Aw: Re: Odd behaviour with StatelessForm and onInitialize()

2023-12-01 Thread Bas Gooren
Hi Daniel,

I did some debugging, and found out why this is not working as expected.

When you add your components to the page in onInitialize(), the following
happens:

Wicket runs a ListenerRequestHandler for the form submit.
That handler tries to find the form component, and does not find it
(PageAndComponentProvider#getComponent) and then initializes the page +
calls beforeRender() on the page.
Through beforeRender, the components in the page are configured
(onConfigure() is called).
This is where your behavior hides the label.
After the form submit is processed, wicket schedules a
RenderPageRequestHandler (in ListenerRequestHandler#internalInvoke).
Normally I’d expect the page to be configured & rendered again at that
point, but because the label was already configured before, it stays hidden.

My first idea was to call Page#configure() in your Form#onSubmit method,
but that didn’t do anything, because configure ensures the logic only runs
once per render (by setting some flags).

My second idea was to detach the page, which did the trick in your example.
Detaching the page forces a re-render after the form submit.

More specifically:

Form form = new StatelessForm<>( "form" )
{
@Override
protected String getMethod()
{
return "GET";
}

@Override
protected void onSubmit()
{
super.onSubmit();

System.out.println( "Form submit" );

getPage().detach();
}
};

Conclusion: try if that works for you in your actual code.
There is differences in how things are handled by wicket depending on where
you add (form) components to your page (in ctor or in onInitialize).

Perhaps one of the core devs can comment on if what I found to happen is
desired behavior (components not configured after form submit in stateless
page, when components are added in onInitialize).

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 30 november 2023 bij 16:45:48, ihmehlm...@gmx.de (ihmehlm...@gmx.de)
schreef:

Hello!

I now uploaded the whole quickstart. It's basicly the same as in my initial
post though just with some added debugging code, so not sure it helps more.
https://drive.google.com/file/d/1UWm3eEf4ddzRy0QeI0DdhsPB7bT2gRcm/view?usp=sharing

The page is the same for both cases and it is indeed supposed to be
stateless.
Simply (un)commenting the initComponents() method in either the page's
constructur or the onInitialize() method changes how the page behaves.
The goal in this quickstart is, that the entered text gets displayed, which
right now doesn't seem to work, if I add my components in the
onInitialize() method.

Adding the components in the constructor prints the following when
submitting the form:

--Constructor--
init components
before super.onInitialize
after super.onInitialize
<< get
>> set <- Setter called before the Behavior
calling get from Behavior
<< get
Setting visibility to true
<< get
<< get

Here you can see, that the setter of the Model is call before the Behavior
is evaluated.
With a value being in the model, the Behavior sets the visibility of the
label to true.


Adding the components in the onInitialize() method prints the following
when submitting the form:

--Constructor--
before super.onInitialize
after super.onInitialize
init components
calling get from Behavior
<< get
Setting visibility to false
<< get
>> set <- Setter called after the Behavior
<< get

Here though you can see, that the setter of the Model is called after the
Behavior is evaluated.
So at the time of evaluation there is no value in the the Model and the
Behavior sets the visibility of the label to false.

If there is anything else I can provide I'll happily do so.

Daniel


Gesendet: Mittwoch, 29. November 2023 um 07:03 Uhr
Von: "Bas Gooren" 
An: users@wicket.apache.org, ihmehlm...@gmx.de
Betreff: Re: Odd behaviour with StatelessForm and onInitialize()
Hi!

Can you share some code? (e.g. a quickstart which reproduces your issue)

It sounds to me like in the one case you are dealing with a stateless page,
and the other a stateful page.

In general, with stateless pages, everything is initialized on every render
/ submit, because there is no page instance (since the page is stateless).
If in some conditions you see that your behavior is run before the submit,
it sounds like you’re dealing with a stateless page. If in other conditions
the behavior is only run on initial page render and after the submit, it
sounds like you’re dealing with a stateful page.

But this is just me guessing without looking at your code.

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 23 november 2023 bij 16:09:53, ihmehlm...@gmx.de (ihmehlm...@gmx.de)
schreef:

Hello,
upon working with StatelessForms for the first time I stumbled up an odd
behav

Aw: Re: Odd behaviour with StatelessForm and onInitialize()

2023-11-30 Thread ihmehlmenn
Hello!

I now uploaded the whole quickstart. It's basicly the same as in my initial 
post though just with some added debugging code, so not sure it helps more.
https://drive.google.com/file/d/1UWm3eEf4ddzRy0QeI0DdhsPB7bT2gRcm/view?usp=sharing

The page is the same for both cases and it is indeed supposed to be stateless.
Simply (un)commenting the initComponents() method in either the page's 
constructur or the onInitialize() method changes how the page behaves.
The goal in this quickstart is, that the entered text gets displayed, which 
right now doesn't seem to work, if I add my components in the onInitialize() 
method.

Adding the components in the constructor prints the following when submitting 
the form:

--Constructor--
init components
before super.onInitialize
after super.onInitialize
<< get
>> set<- Setter called before the Behavior
calling get from Behavior
<< get
Setting visibility to true
<< get
<< get

Here you can see, that the setter of the Model is call before the Behavior is 
evaluated.
With a value being in the model, the Behavior sets the visibility of the label 
to true.


Adding the components in the onInitialize() method prints the following when 
submitting the form:

--Constructor--
before super.onInitialize
after super.onInitialize
init components
calling get from Behavior
<< get
Setting visibility to false
<< get
>> set<- Setter called after the Behavior
<< get

Here though you can see, that the setter of the Model is called after the 
Behavior is evaluated.
So at the time of evaluation there is no value in the the Model and the 
Behavior sets the visibility of the label to false.

If there is anything else I can provide I'll happily do so.

Daniel


Gesendet: Mittwoch, 29. November 2023 um 07:03 Uhr
Von: "Bas Gooren" 
An: users@wicket.apache.org, ihmehlm...@gmx.de
Betreff: Re: Odd behaviour with StatelessForm and onInitialize()
Hi!

Can you share some code? (e.g. a quickstart which reproduces your issue)

It sounds to me like in the one case you are dealing with a stateless page,
and the other a stateful page.

In general, with stateless pages, everything is initialized on every render
/ submit, because there is no page instance (since the page is stateless).
If in some conditions you see that your behavior is run before the submit,
it sounds like you’re dealing with a stateless page. If in other conditions
the behavior is only run on initial page render and after the submit, it
sounds like you’re dealing with a stateful page.

But this is just me guessing without looking at your code.

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 23 november 2023 bij 16:09:53, ihmehlm...@gmx.de (ihmehlm...@gmx.de)
schreef:

Hello,
upon working with StatelessForms for the first time I stumbled up an odd
behavior in regards to when the corresponding models are updated.

Following setup:

The base for this is a wicket quickstart 9.15.0. I modified the two
HomePage files, which can be found here:
https://gist.github.com/TekkiWuff/824e820427c16e204bde68e95fd566a6

In this I have a Page with a StatelessForm with a single TextField and a
Label. The TextField and Label share a single String-Model. The Label has a
Behavior which sets the visibility of the attached component to false in
the configure-phase if the String-Model is empty.
Here this is needed to hide the whole HTML-tag instead of rendering an
empty li-tag. In my actual application this applies to much bigger and more
complex panels and lists which need to be hidden/shown when certain form
values are set/not set.


Now the to me odd behavior:

If I initialise all components in the constructor of the page, everything
works as expected.
The request of the form submit gets processed, the model updated and then
afterwards the page gets rendered among which also the Behaviour is run to
set the visibility of the label.
So the visibility is decided on the just submitted form value.

Now if I initialise all components in the onInitialize() method, which by
my understanding is supposed to work like the constructor, the order of
execution seems wrong.
First, my Behaviour is run to set the visibility. Then the request of the
form submit gets processed, the model updated and the page rendered.
So here now the visibility is suddenly decided on the old value, which in
my case initially is an empty Model, so my Label is always hidden.

It's not a matter of using GET or POST and only seems to happen with
StatelessForm. Using a normal statefull Form is working just fine.

Is this a bug or an expected behaviour? I couldn't find anything about this
in the description of the StatelessForm about this.
I am exclusivly using the onInitialize() method for constructing all my
pages, so before having to change several hundred pages to using the
constructor, I rather ask first if it's maybe something that can be fixed.

Regards
Daniel

---

Re: Odd behaviour with StatelessForm and onInitialize()

2023-11-28 Thread Bas Gooren
Hi!

Can you share some code? (e.g. a quickstart which reproduces your issue)

It sounds to me like in the one case you are dealing with a stateless page,
and the other a stateful page.

In general, with stateless pages, everything is initialized on every render
/ submit, because there is no page instance (since the page is stateless).
If in some conditions you see that your behavior is run before the submit,
it sounds like you’re dealing with a stateless page. If in other conditions
the behavior is only run on initial page render and after the submit, it
sounds like you’re dealing with a stateful page.

But this is just me guessing without looking at your code.

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 23 november 2023 bij 16:09:53, ihmehlm...@gmx.de (ihmehlm...@gmx.de)
schreef:

Hello,
upon working with StatelessForms for the first time I stumbled up an odd
behavior in regards to when the corresponding models are updated.

Following setup:

The base for this is a wicket quickstart 9.15.0. I modified the two
HomePage files, which can be found here:
https://gist.github.com/TekkiWuff/824e820427c16e204bde68e95fd566a6

In this I have a Page with a StatelessForm with a single TextField and a
Label. The TextField and Label share a single String-Model. The Label has a
Behavior which sets the visibility of the attached component to false in
the configure-phase if the String-Model is empty.
Here this is needed to hide the whole HTML-tag instead of rendering an
empty li-tag. In my actual application this applies to much bigger and more
complex panels and lists which need to be hidden/shown when certain form
values are set/not set.


Now the to me odd behavior:

If I initialise all components in the constructor of the page, everything
works as expected.
The request of the form submit gets processed, the model updated and then
afterwards the page gets rendered among which also the Behaviour is run to
set the visibility of the label.
So the visibility is decided on the just submitted form value.

Now if I initialise all components in the onInitialize() method, which by
my understanding is supposed to work like the constructor, the order of
execution seems wrong.
First, my Behaviour is run to set the visibility. Then the request of the
form submit gets processed, the model updated and the page rendered.
So here now the visibility is suddenly decided on the old value, which in
my case initially is an empty Model, so my Label is always hidden.

It's not a matter of using GET or POST and only seems to happen with
StatelessForm. Using a normal statefull Form is working just fine.

Is this a bug or an expected behaviour? I couldn't find anything about this
in the description of the StatelessForm about this.
I am exclusivly using the onInitialize() method for constructing all my
pages, so before having to change several hundred pages to using the
constructor, I rather ask first if it's maybe something that can be fixed.

Regards
Daniel

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


Aw: Re: Odd behaviour with StatelessForm and onInitialize()

2023-11-28 Thread ihmehlmenn
Thanks for the idea, but there doesn't seem to be any difference between adding 
the components before or after calling super.onInitialize()
 

Gesendet: Freitag, 24. November 2023 um 13:56 Uhr
Von: "Martin Grigorov" 
An: users@wicket.apache.org
Betreff: Re: Odd behaviour with StatelessForm and onInitialize()
Hi,

I don't have time to debug the problem right now but could you try
something: swap these two lines -
https://gist.github.com/TekkiWuff/824e820427c16e204bde68e95fd566a6#file-homepage-java-L25-L26
I.e. first add() the components to the page and then call
super.onInitialize()

On Thu, Nov 23, 2023 at 5:09 PM  wrote:

> Hello,
> upon working with StatelessForms for the first time I stumbled up an odd
> behavior in regards to when the corresponding models are updated.
>
> Following setup:
>
> The base for this is a wicket quickstart 9.15.0. I modified the two
> HomePage files, which can be found here:
> https://gist.github.com/TekkiWuff/824e820427c16e204bde68e95fd566a6[https://gist.github.com/TekkiWuff/824e820427c16e204bde68e95fd566a6]
>
> In this I have a Page with a StatelessForm with a single TextField and a
> Label. The TextField and Label share a single String-Model. The Label has a
> Behavior which sets the visibility of the attached component to false in
> the configure-phase if the String-Model is empty.
> Here this is needed to hide the whole HTML-tag instead of rendering an
> empty li-tag. In my actual application this applies to much bigger and more
> complex panels and lists which need to be hidden/shown when certain form
> values are set/not set.
>
>
> Now the to me odd behavior:
>
> If I initialise all components in the constructor of the page, everything
> works as expected.
> The request of the form submit gets processed, the model updated and then
> afterwards the page gets rendered among which also the Behaviour is run to
> set the visibility of the label.
> So the visibility is decided on the just submitted form value.
>
> Now if I initialise all components in the onInitialize() method, which by
> my understanding is supposed to work like the constructor, the order of
> execution seems wrong.
> First, my Behaviour is run to set the visibility. Then the request of the
> form submit gets processed, the model updated and the page rendered.
> So here now the visibility is suddenly decided on the old value, which in
> my case initially is an empty Model, so my Label is always hidden.
>
> It's not a matter of using GET or POST and only seems to happen with
> StatelessForm. Using a normal statefull Form is working just fine.
>
> Is this a bug or an expected behaviour? I couldn't find anything about
> this in the description of the StatelessForm about this.
> I am exclusivly using the onInitialize() method for constructing all my
> pages, so before having to change several hundred pages to using the
> constructor, I rather ask first if it's maybe something that can be fixed.
>
> Regards
> Daniel
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

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



Re: Odd behaviour with StatelessForm and onInitialize()

2023-11-24 Thread Martin Grigorov
Hi,

I don't have time to debug the problem right now but could you try
something: swap these two lines -
https://gist.github.com/TekkiWuff/824e820427c16e204bde68e95fd566a6#file-homepage-java-L25-L26
I.e. first add() the components to the page and then call
super.onInitialize()

On Thu, Nov 23, 2023 at 5:09 PM  wrote:

> Hello,
> upon working with StatelessForms for the first time I stumbled up an odd
> behavior in regards to when the corresponding models are updated.
>
> Following setup:
>
> The base for this is a wicket quickstart 9.15.0. I modified the two
> HomePage files, which can be found here:
> https://gist.github.com/TekkiWuff/824e820427c16e204bde68e95fd566a6
>
> In this I have a Page with a StatelessForm with a single TextField and a
> Label. The TextField and Label share a single String-Model. The Label has a
> Behavior which sets the visibility of the attached component to false in
> the configure-phase if the String-Model is empty.
> Here this is needed to hide the whole HTML-tag instead of rendering an
> empty li-tag. In my actual application this applies to much bigger and more
> complex panels and lists which need to be hidden/shown when certain form
> values are set/not set.
>
>
> Now the to me odd behavior:
>
> If I initialise all components in the constructor of the page, everything
> works as expected.
> The request of the form submit gets processed, the model updated and then
> afterwards the page gets rendered among which also the Behaviour is run to
> set the visibility of the label.
> So the visibility is decided on the just submitted form value.
>
> Now if I initialise all components in the onInitialize() method, which by
> my understanding is supposed to work like the constructor, the order of
> execution seems wrong.
> First, my Behaviour is run to set the visibility. Then the request of the
> form submit gets processed, the model updated and the page rendered.
> So here now the visibility is suddenly decided on the old value, which in
> my case initially is an empty Model, so my Label is always hidden.
>
> It's not a matter of using GET or POST and only seems to happen with
> StatelessForm. Using a normal statefull Form is working just fine.
>
> Is this a bug or an expected behaviour? I couldn't find anything about
> this in the description of the StatelessForm about this.
> I am exclusivly using the onInitialize() method for constructing all my
> pages, so before having to change several hundred pages to using the
> constructor, I rather ask first if it's maybe something that can be fixed.
>
> Regards
> Daniel
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Odd behaviour with StatelessForm and onInitialize()

2023-11-23 Thread ihmehlmenn
Hello,
upon working with StatelessForms for the first time I stumbled up an odd 
behavior in regards to when the corresponding models are updated.

Following setup:

The base for this is a wicket quickstart 9.15.0. I modified the two HomePage 
files, which can be found here: 
https://gist.github.com/TekkiWuff/824e820427c16e204bde68e95fd566a6

In this I have a Page with a StatelessForm with a single TextField and a Label. 
The TextField and Label share a single String-Model. The Label has a Behavior 
which sets the visibility of the attached component to false in the 
configure-phase if the String-Model is empty.
Here this is needed to hide the whole HTML-tag instead of rendering an empty 
li-tag. In my actual application this applies to much bigger and more complex 
panels and lists which need to be hidden/shown when certain form values are 
set/not set.


Now the to me odd behavior:

If I initialise all components in the constructor of the page, everything works 
as expected.
The request of the form submit gets processed, the model updated and then 
afterwards the page gets rendered among which also the Behaviour is run to set 
the visibility of the label.
So the visibility is decided on the just submitted form value.

Now if I initialise all components in the onInitialize() method, which by my 
understanding is supposed to work like the constructor, the order of execution 
seems wrong.
First, my Behaviour is run to set the visibility. Then the request of the form 
submit gets processed, the model updated and the page rendered.
So here now the visibility is suddenly decided on the old value, which in my 
case initially is an empty Model, so my Label is always hidden.

It's not a matter of using GET or POST and only seems to happen with 
StatelessForm. Using a normal statefull Form is working just fine.

Is this a bug or an expected behaviour? I couldn't find anything about this in 
the description of the StatelessForm about this.
I am exclusivly using the onInitialize() method for constructing all my pages, 
so before having to change several hundred pages to using the constructor, I 
rather ask first if it's maybe something that can be fixed.

Regards
Daniel

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