You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sandor Feher <sf...@bluesystem.hu> on 2012/08/28 17:27:31 UTC

Nested form submit problem

Hi,

I have the following use case. I have some questionnaires and a couple of
questions belong to every questionnaire.
I created a nested form component contains two forms. First does nothing
just has some buttons (save,delete,cancel,reset) and contains as many child
forms as the number of questions.
So it's fine and almost everything work. My problem is when I want to delete
the items and click delete button then the inner form's onSubmit event also
fires although I set the delete.setDefaultFormProcessing(false) behaviour on
delete button. Same is with reset and cancel button. Both of them fires
inner form's onSubmit event.


http://pastebin.com/zErvmG5J

tia, Sandor



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Nested-form-submit-problem-tp4651565.html
Sent from the Users forum mailing list archive at Nabble.com.

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


RE: Nested form submit problem

Posted by Sandor Feher <sf...@bluesystem.hu>.
Many thanks Paul, I will go ahead.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Nested-form-submit-problem-tp4651565p4651608.html
Sent from the Users forum mailing list archive at Nabble.com.

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


RE: Nested form submit problem

Posted by Paul Bors <pa...@bors.ws>.
Looking over your model_copy.png I feel that my original suggestion holds.

* Have each of the rows holding on to the questions as Panels that extend an
interface you come up with to persist the question.
* Have the Repeating view's model be a list of Panels (I usually use
DataTables for this).
* When you submit the outer form, iterate through the repeating view's list
of Panels and call back to the interface methods that your create to persist
each of the questions.

Also you can still look over the Wizard and adopt that to your use-case.
Just think that each of the questions is a step in a Wizard only that you're
displaying all panels at once.

~ Thank you,
  Paul Bors

-----Original Message-----
From: Sandor Feher [mailto:sfeher@bluesystem.hu] 
Sent: Wednesday, August 29, 2012 3:00 AM
To: users@wicket.apache.org
Subject: RE: Nested form submit problem


Paul Bors wrote
> 
> Must you really have a nested form here?
> 
I think yes. I tried to sketch what I need for better understanding. For
example there is a quiestionnarie has five questions. Every question has id
and max points can be given and so one. I store the result in a result table
and get the ids and max points from a param table. So I created a form for
buttons and as many nested forms as questions I have. Every questions has
it's own model because they will be stored in different records.
The main goal is to submit once and persist all of the nested models while
get value field validated at field level. The problem is that I can only
persist my models at nested form's level on onSubmit event while onSubmit
fires even I click on reset or delete or whatever on the parent form.
I hope it's more clear now and sorry for making noise. Please suggest what
could be the best approach to achieve this. 

TIA, Sandor


http://apache-wicket.1842946.n4.nabble.com/file/n4651589/modell_copy.png 



--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Nested-form-submit-problem-tp4651
565p4651589.html
Sent from the Users forum mailing list archive at Nabble.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: Nested form submit problem

Posted by Sandor Feher <sf...@bluesystem.hu>.
Paul Bors wrote
> 
> Must you really have a nested form here?
> 
I think yes. I tried to sketch what I need for better understanding. For
example there is a quiestionnarie has five questions. Every question has id
and max points can be given and so one. I store the result in a result table
and get the ids and max points from a param table. So I created a form for
buttons and as many nested forms as questions I have. Every questions has
it's own model because they will be stored in different records.
The main goal is to submit once and persist all of the nested models while
get value field validated at field level. The problem is that I can only
persist my models at nested form's level on onSubmit event while onSubmit
fires even I click on reset or delete or whatever on the parent form.
I hope it's more clear now and sorry for making noise. Please suggest what
could be the best approach to achieve this. 

TIA, Sandor


http://apache-wicket.1842946.n4.nabble.com/file/n4651589/modell_copy.png 



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Nested-form-submit-problem-tp4651565p4651589.html
Sent from the Users forum mailing list archive at Nabble.com.

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


RE: Nested form submit problem

Posted by Paul Bors <pa...@bors.ws>.
Must you really have a nested form here?
Can't you just get away with having each form field in a panel and not
surround it with a second form html tag?

And if you must really do so... can't you toggle that html form tag between
a Wicket Form and WebMarkupContainer or EmptyPanel (hide it when used as a
WebMarkupContainer or EmptyPanel so your wicket component tree is preserved
but it won't render on your page). You would have to keep state for each of
those "inner panel forms" of yours.

Those are just couple of ideas to get you started with.

Also, take a look at the Wizard as that component uses different panels to
add form field on different Steps of the Wizard.
See it in action at:
http://www.wicket-library.com/wicket-examples/wizard

~ Thank you,
  Paul Bors

-----Original Message-----
From: Sandor Feher [mailto:sfeher@bluesystem.hu] 
Sent: Tuesday, August 28, 2012 5:54 PM
To: users@wicket.apache.org
Subject: RE: Nested form submit problem

This works until I submit the parent form because it fires nested form's
onSubmit event. Does not matter if I click on save or cancel or whatever
button. 
Anyway. Is it possible to catch the button name clicked in the nested form
onSubmit ? If so I could separate the code depending on the button clicked.

   



--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Nested-form-submit-problem-tp4651
565p4651576.html
Sent from the Users forum mailing list archive at Nabble.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: Nested form submit problem

Posted by Sandor Feher <sf...@bluesystem.hu>.
This works until I submit the parent form because it fires nested form's
onSubmit event. Does not matter if I click on save or cancel or whatever
button. 
Anyway. Is it possible to catch the button name clicked in the nested form
onSubmit ? If so I could separate the code depending on the button clicked.

   



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Nested-form-submit-problem-tp4651565p4651576.html
Sent from the Users forum mailing list archive at Nabble.com.

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


RE: Nested form submit problem

Posted by Paul Bors <pa...@bors.ws>.
Why not use "onchange" and validate the field when the user changes the
input?

All you would have to do is add your validators as you would normally do,
then create Ajax*** form components and in their callback method for
onError(target) refresh your feedback panel.

A text field with this design applied to it will validate the user input for
each character typed, use a different JS event for other behavior.

For code examples see:
http://www.wicket-library.com/wicket-examples/ajax/form

~ Thank you,
  Paul Bors

-----Original Message-----
From: Sandor Feher [mailto:sfeher@bluesystem.hu] 
Sent: Tuesday, August 28, 2012 3:37 PM
To: users@wicket.apache.org
Subject: RE: Nested form submit problem

Hi Paul,

The problem related to AjaxFormSubmitBehavior  behaviour. This fires eform's
onSubmit event.
My original goal was to create field level validation with Ajax nothing
more.
The code above looks for a description belongs to the entered value and
displays it.
If the entered value validation failed then warns the user immediately. 
BTW if I turn of afvb setDefaultFormProcessing to false then the field level
validation does not work.


-----------------------
              AjaxFormSubmitBehavior afvb=
                new AjaxFormSubmitBehavior(eform, "onchange") {
                 
 
                    @Override
                    protected void onSubmit(AjaxRequestTarget art) {
                        HrpBbheertk ertk = (HrpBbheertk)
eform.getModelObject();
                        String k = ertek.getValue();
                        customBo.getDaoSession().beginTransaction();
                        HrpBbhepar5PK pk = new HrpBbhepar5PK();
                        pk.setCompany(ertk.getHrpBbheertkPK().getCompany());
                       
pk.setAkodszam(ertk.getHrpBbheertkPK().getAlaptipus());
                       
pk.setDkodszam(ertk.getHrpBbheertkPK().getDimenzio());
                       
pk.setDekodszam(ertk.getHrpBbheertkPK().getDimenzioelem());
                        if (!k.isEmpty()) {
                            pk.setDertek(Short.valueOf(k));
                            HrpBbhepar5 hepar5 =
customBo.find(HrpBbhepar5.class, pk);
                            if (hepar5 != null) {
                               
dimenev.setDefaultModelObject(hepar5.getDertekmegnev());
                            } else {
                                dimenev.setDefaultModelObject("");
                            }

                        }
                        if
(customBo.getDaoSession().getTransaction().isActive()) {
                           
customBo.getDaoSession().getTransaction().commit();
                        }

                        art.add(dimenev);
                        art.add(fb);
                    }

                    @Override
                    protected void onError(AjaxRequestTarget art) { 
                        art.add(fb);
                    }

                };



--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Nested-form-submit-problem-tp4651
565p4651568.html
Sent from the Users forum mailing list archive at Nabble.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: Nested form submit problem

Posted by Sandor Feher <sf...@bluesystem.hu>.
Hi Paul,

The problem related to AjaxFormSubmitBehavior  behaviour. This fires eform's
onSubmit event.
My original goal was to create field level validation with Ajax nothing
more.
The code above looks for a description belongs to the entered value and
displays it.
If the entered value validation failed then warns the user immediately. 
BTW if I turn of afvb setDefaultFormProcessing to false then the field level
validation does not work.


-----------------------
              AjaxFormSubmitBehavior afvb=
                new AjaxFormSubmitBehavior(eform, "onchange") {
                 
 
                    @Override
                    protected void onSubmit(AjaxRequestTarget art) {
                        HrpBbheertk ertk = (HrpBbheertk)
eform.getModelObject();
                        String k = ertek.getValue();
                        customBo.getDaoSession().beginTransaction();
                        HrpBbhepar5PK pk = new HrpBbhepar5PK();
                        pk.setCompany(ertk.getHrpBbheertkPK().getCompany());
                       
pk.setAkodszam(ertk.getHrpBbheertkPK().getAlaptipus());
                       
pk.setDkodszam(ertk.getHrpBbheertkPK().getDimenzio());
                       
pk.setDekodszam(ertk.getHrpBbheertkPK().getDimenzioelem());
                        if (!k.isEmpty()) {
                            pk.setDertek(Short.valueOf(k));
                            HrpBbhepar5 hepar5 =
customBo.find(HrpBbhepar5.class, pk);
                            if (hepar5 != null) {
                               
dimenev.setDefaultModelObject(hepar5.getDertekmegnev());
                            } else {
                                dimenev.setDefaultModelObject("");
                            }

                        }
                        if
(customBo.getDaoSession().getTransaction().isActive()) {
                           
customBo.getDaoSession().getTransaction().commit();
                        }

                        art.add(dimenev);
                        art.add(fb);
                    }

                    @Override
                    protected void onError(AjaxRequestTarget art) { 
                        art.add(fb);
                    }

                };



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Nested-form-submit-problem-tp4651565p4651568.html
Sent from the Users forum mailing list archive at Nabble.com.

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


RE: Nested form submit problem

Posted by Paul Bors <pa...@bors.ws>.
Sounds complicated, why not just setVisible(false) when you want to "delete"
or hide one of those questions (aka form fields)?
Also, I don't think you need to use nested forms here, unless you wrap each
question in a panel and within in a form.

Refer to this wiki page for nested forms and their behavior:
https://cwiki.apache.org/WICKET/nested-forms.html

Is hard to follow the code example you gave but if I understand your
use-case right and if you want to add different questions within a form I
suggest you use a DataTable and a dynamic DataProvider that would be
populated with a list of Panels that hold on to each of the labels and form
fields with the questions you want to show (no need for an inner form unless
you want the question to be answered by itself). When you want to hide one
of them simply call setVisible(false) and use Ajax to refresh the DataTable.
If you want to change the questions, simply change the list of Panels and
make sure each form field has its own model (or use CompoundModel if you
want).

Hope that helps :)

~ Thank you,
  Paul Bors

-----Original Message-----
From: Sandor Feher [mailto:sfeher@bluesystem.hu] 
Sent: Tuesday, August 28, 2012 11:28 AM
To: users@wicket.apache.org
Subject: Nested form submit problem

Hi,

I have the following use case. I have some questionnaires and a couple of
questions belong to every questionnaire.
I created a nested form component contains two forms. First does nothing
just has some buttons (save,delete,cancel,reset) and contains as many child
forms as the number of questions.
So it's fine and almost everything work. My problem is when I want to delete
the items and click delete button then the inner form's onSubmit event also
fires although I set the delete.setDefaultFormProcessing(false) behaviour on
delete button. Same is with reset and cancel button. Both of them fires
inner form's onSubmit event.


http://pastebin.com/zErvmG5J

tia, Sandor



--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Nested-form-submit-problem-tp4651
565.html
Sent from the Users forum mailing list archive at Nabble.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: Nested form submit problem

Posted by Sandor Feher <sf...@bluesystem.hu>.
Be sure :). This is the root of all evil :). Checked.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Nested-form-submit-problem-tp4651565p4651575.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Nested form submit problem

Posted by Andrea Del Bene <an...@gmail.com>.
I'm not 100% sure, but I think your inner form is submitted by the 
AjaxFormValidatingBehavior attached to textfield ertek. Try to remove it 
to see if the form is still submitted.
> Hi,
>
> I have the following use case. I have some questionnaires and a couple of
> questions belong to every questionnaire.
> I created a nested form component contains two forms. First does nothing
> just has some buttons (save,delete,cancel,reset) and contains as many child
> forms as the number of questions.
> So it's fine and almost everything work. My problem is when I want to delete
> the items and click delete button then the inner form's onSubmit event also
> fires although I set the delete.setDefaultFormProcessing(false) behaviour on
> delete button. Same is with reset and cancel button. Both of them fires
> inner form's onSubmit event.
>
>
> http://pastebin.com/zErvmG5J
>
> tia, Sandor
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Nested-form-submit-problem-tp4651565.html
> Sent from the Users forum mailing list archive at Nabble.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