Re: Empty form values after successful onSubmit?
Guten Tag Martin Grigorov, am Dienstag, 3. Februar 2015 um 09:28 schrieben Sie: > You can use getSession().success(...) instead if you know there is a > session, or it is OK to bind one. Thanks for that hint, I indeed always have a session in my context. > I meant to set a new instance of YourEntity in the Form's model. Not to > create a new instance of the Form itself. I use a CompoundPropertyModel with the form itself as a model, so in that scenario I shouldn't set a new model instance manually just to empty values? > It is really up to *your* use case and wanted user experience That was my impression as well, I just wanted to be clear if I don't miss any best practice or am doing something wrong. Thanks a lot! Mit freundlichen Grüßen, Thorsten Schöning -- Thorsten Schöning E-Mail: thorsten.schoen...@am-soft.de AM-SoFT IT-Systeme http://www.AM-SoFT.de/ Telefon...05151- 9468- 55 Fax...05151- 9468- 88 Mobil..0178-8 9468- 04 AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Empty form values after successful onSubmit?
Hi, On Tue, Feb 3, 2015 at 10:14 AM, Thorsten Schöning wrote: > Guten Tag Sven Meier, > am Montag, 2. Februar 2015 um 21:03 schrieben Sie: > > > You can navigate to a new page instance > > (#setResponsePage(this.getClass()) if you want to start over with empty > > input *and* an empty model. > > Tried that and indeed the form values are empty in that case, but my > "success" message is not rendered anymore. > Because the success feedback message is associated with a Component that is not rendered due to the redirect. You can use getSession().success(...) instead if you know there is a session, or it is OK to bind one. > > Guten Tag Martin Grigorov, > am Montag, 2. Februar 2015 um 21:59 schrieben Sie: > > > Or set a fresh instance as a model object of the Form. > > That rendered my "success" message without any old model values. Is > that a workaround or something one can do without risking problems? It > feels a bit strange to always create a new form instance which is only > used as the model, while the first created instance added by the page > is kept around for the page. > I meant to set a new instance of YourEntity in the Form's model. Not to create a new instance of the Form itself. Wicket renders the page components by using their models. After successful submit the Form model object is fully populated and that's why the form elements have values in the generated markup. Wicket tries to not do any magic, so it doesn't empty-fy the models automatically. Even if Wicket was supposed to make them empty the only possible way is to set them to null, because Wicket doesn't introspect the object used as a model object. Suppose that the Form uses a Person model object. If Wicket sets the person to null then trying to set his first name with any following submit will do: null.setFirstName("some new value"). This will lead to NullPointerException. Another way is to assume that *your* model objects (i.e. Person class) always have a default constructor. But Wicket doesn't prescribe how your model objects should look like. So after successful submit it is up to the developer to decide what to show to the end user: i) a confirmation page ii) an empty form with success message near by iii) a populated form iv) half-populated form It is really up to *your* use case and wanted user experience > Would it be a better solution to just empty the only one created > instance of the form by the page, which I already have anyways and is > used as default model? > > Mit freundlichen Grüßen, > > Thorsten Schöning > > -- > Thorsten Schöning E-Mail: thorsten.schoen...@am-soft.de > AM-SoFT IT-Systeme http://www.AM-SoFT.de/ > > Telefon...05151- 9468- 55 > Fax...05151- 9468- 88 > Mobil..0178-8 9468- 04 > > AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln > AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow > > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >
Re: Empty form values after successful onSubmit?
Guten Tag Sven Meier, am Montag, 2. Februar 2015 um 21:03 schrieben Sie: > You can navigate to a new page instance > (#setResponsePage(this.getClass()) if you want to start over with empty > input *and* an empty model. Tried that and indeed the form values are empty in that case, but my "success" message is not rendered anymore. Guten Tag Martin Grigorov, am Montag, 2. Februar 2015 um 21:59 schrieben Sie: > Or set a fresh instance as a model object of the Form. That rendered my "success" message without any old model values. Is that a workaround or something one can do without risking problems? It feels a bit strange to always create a new form instance which is only used as the model, while the first created instance added by the page is kept around for the page. Would it be a better solution to just empty the only one created instance of the form by the page, which I already have anyways and is used as default model? Mit freundlichen Grüßen, Thorsten Schöning -- Thorsten Schöning E-Mail: thorsten.schoen...@am-soft.de AM-SoFT IT-Systeme http://www.AM-SoFT.de/ Telefon...05151- 9468- 55 Fax...05151- 9468- 88 Mobil..0178-8 9468- 04 AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Empty form values after successful onSubmit?
On Mon, Feb 2, 2015 at 10:03 PM, Sven Meier wrote: > Hi, > > I don't think you're doing something weird, you're just seeing the normal > Wicket behavior: > > >I debugged a bit > > Good! > > >that "success" calls though to some logic which marks my page as dirty > >generated a new version number, stores the changed page in the session > > All pretty normal. > > >I don't see anything to interfere with that > > Why should you? > > > the ctor of my page is not called again > > the same with onInitialization > > Why should it? > > Wicket is stateful by default, so it will keep the current page as long as > the user doesn't navigate away from it. > Wicket pages are stateless by default. It is just that it is very easy to become stateful. > > After form processing the input of all form components are cleared, but > after that you see the model values instead. > You can navigate to a new page instance (#setResponsePage(this.getClass()) > if you want to start over with empty input *and* an empty model. > Or set a fresh instance as a model object of the Form. > > Regards > Sven > > > On 02.02.2015 18:34, Thorsten Schöning wrote: > >> Guten Tag Thorsten Schöning, >> am Montag, 2. Februar 2015 um 18:13 schrieben Sie: >> >> I do see the success message AND the values of the input which have >>> been sent. >>> >> I debugged a bit and can verify that "success" calls though to some >> logic which marks my page as dirty, generated a new version number, >> stores the changed page in the session and such. I don't see anything >> to interfere with that and the ctor of my page is not called again, >> the same with onInitialization, which I override to build my form. >> >> I didn't see any code which resets the default model or its properties >> or such. >> >> Is all that expected and intended behavior or am I doing something >> really weird? :-) >> >> Mit freundlichen Grüßen, >> >> Thorsten Schöning >> >> > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >
Re: Empty form values after successful onSubmit?
Hi, I don't think you're doing something weird, you're just seeing the normal Wicket behavior: >I debugged a bit Good! >that "success" calls though to some logic which marks my page as dirty >generated a new version number, stores the changed page in the session All pretty normal. >I don't see anything to interfere with that Why should you? > the ctor of my page is not called again > the same with onInitialization Why should it? Wicket is stateful by default, so it will keep the current page as long as the user doesn't navigate away from it. After form processing the input of all form components are cleared, but after that you see the model values instead. You can navigate to a new page instance (#setResponsePage(this.getClass()) if you want to start over with empty input *and* an empty model. Regards Sven On 02.02.2015 18:34, Thorsten Schöning wrote: Guten Tag Thorsten Schöning, am Montag, 2. Februar 2015 um 18:13 schrieben Sie: I do see the success message AND the values of the input which have been sent. I debugged a bit and can verify that "success" calls though to some logic which marks my page as dirty, generated a new version number, stores the changed page in the session and such. I don't see anything to interfere with that and the ctor of my page is not called again, the same with onInitialization, which I override to build my form. I didn't see any code which resets the default model or its properties or such. Is all that expected and intended behavior or am I doing something really weird? :-) Mit freundlichen Grüßen, Thorsten Schöning - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Empty form values after successful onSubmit?
Guten Tag Thorsten Schöning, am Montag, 2. Februar 2015 um 18:13 schrieben Sie: > I do see the success message AND the values of the input which have > been sent. I debugged a bit and can verify that "success" calls though to some logic which marks my page as dirty, generated a new version number, stores the changed page in the session and such. I don't see anything to interfere with that and the ctor of my page is not called again, the same with onInitialization, which I override to build my form. I didn't see any code which resets the default model or its properties or such. Is all that expected and intended behavior or am I doing something really weird? :-) Mit freundlichen Grüßen, Thorsten Schöning -- Thorsten Schöning E-Mail: thorsten.schoen...@am-soft.de AM-SoFT IT-Systeme http://www.AM-SoFT.de/ Telefon...05151- 9468- 55 Fax...05151- 9468- 88 Mobil..0178-8 9468- 04 AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Empty form values after successful onSubmit?
Guten Tag Sven Meier, am Montag, 2. Februar 2015 um 17:38 schrieben Sie: > a Form clears all FormComponents' input automatically on a successful > submit. > Why do you think that this is not the case? Because that's what I see. ;-) Using the following code: >@Override >protected void onSubmit() >{ >do something... > >// TODO Instanzdaten leeren? >this.success(this.getString("success")); >} I do see the success message AND the values of the input which have been sent. So, you tell me that I'm doing something wrong? I only have a form and use it as a compound one as the default model. Any ideas on where I should look at to find the problem? Thank! Mit freundlichen Grüßen, Thorsten Schöning -- Thorsten Schöning E-Mail: thorsten.schoen...@am-soft.de AM-SoFT IT-Systeme http://www.AM-SoFT.de/ Telefon...05151- 9468- 55 Fax...05151- 9468- 88 Mobil..0178-8 9468- 04 AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Empty form values after successful onSubmit?
Hi Thorsten, a Form clears all FormComponents' input automatically on a successful submit. Why do you think that this is not the case? Regards Sven On 02.02.2015 17:11, Thorsten Schöning wrote: Hi all, I have some very straightforward forms, but am really new to the whole stateful forms/pages thing in Wicket. My form has some elements with validators and if things fail the form is rendered again with the former input values and a feedback message with the error. If no error occured my form changes some data and provides a simple "success" feedback message by calling "this.success(...)". I didn't expect the latter, but instead that the form data is cleared automatically. Is that something Wicket don't want to do automatically by purpose because it's only sometimes wanted, not always? I'm a bit afraid I could forget clearing data on my own in that case and thought about how to deal with this, especially as forms may grow in future and fields get added. I'm using CompoundPropertyModel, like suggested in the tutorials. Any ideas or suggestions on this? Would be a simple call to Form.clearInput the best solution? Thank für your feedback! Mit freundlichen Grüßen, Thorsten Schöning - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org