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" <b...@iswd.nl>
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

---------------------------------------------------------------------
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

Reply via email to