Ajax:submit formcomponent with ajaxbutton

View: New views
3 Messages — Rating Filter:   Alert me  

Ajax:submit formcomponent with ajaxbutton

by Marieke Vandamme :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I think I can explain it best with an example :

TextField txt = new TextField("txt");
WebMarkupContainer btn = new WebMarkupContainer("btn");
btn.add(new AjaxFormComponentUpdatingBehavior("onclick", txt);

=> I want to submit the value of another formcomponent when clicking on the button.

I know I can use an AjaxButton or a AjaxFormSubmitBehavior instead, but than all the fields on my form are submitted, and I only want this one field. There are a lot of fields on my form, and it's not necessary to submit all of them and then I have to deal with the validation of my form and so..

Is this possible in any way? Are is it something that can be added to the AjaxFormComponentUpdatingBehavior class?
Thanks ! Marieke

Re: Ajax:submit formcomponent with ajaxbutton

by Michael Sparer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

yes this is possible, you can nest forms in wicket. Just make a form in a form in both your markup and your code. As this doesn't conform the html standard, wicket will automagically change the second form to a div and only submit the inner form. But be careful when submitting the outer form ... if I remember correctly, then the inner form gets submitted as well.... however I'm not sure about that.

regards,
Michael
Marieke Vandamme wrote:
Hello,

I think I can explain it best with an example :

TextField txt = new TextField("txt");
WebMarkupContainer btn = new WebMarkupContainer("btn");
btn.add(new AjaxFormComponentUpdatingBehavior("onclick", txt);

=> I want to submit the value of another formcomponent when clicking on the button.

I know I can use an AjaxButton or a AjaxFormSubmitBehavior instead, but than all the fields on my form are submitted, and I only want this one field. There are a lot of fields on my form, and it's not necessary to submit all of them and then I have to deal with the validation of my form and so..

Is this possible in any way? Are is it something that can be added to the AjaxFormComponentUpdatingBehavior class?
Thanks ! Marieke

Re: Ajax:submit formcomponent with ajaxbutton

by Marieke Vandamme :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


That works perfectly indeed.
Always thought that nested forms would break in html, but wicket converts them to a div indeed. that's so clever. I already told my colleagues, and it's definitely something we'll use frequently.
Thanks a lot !
kind regards, Marieke


Hi,

yes this is possible, you can nest forms in wicket. Just make a form in a form in both your markup and your code. As this doesn't conform the html standard, wicket will automagically change the second form to a div and only submit the inner form. But be careful when submitting the outer form ... if I remember correctly, then the inner form gets submitted as well.... however I'm not sure about that.

regards,
Michael
Marieke Vandamme wrote:
Hello,

I think I can explain it best with an example :

TextField txt = new TextField("txt");
WebMarkupContainer btn = new WebMarkupContainer("btn");
btn.add(new AjaxFormComponentUpdatingBehavior("onclick", txt);

=> I want to submit the value of another formcomponent when clicking on the button.

I know I can use an AjaxButton or a AjaxFormSubmitBehavior instead, but than all the fields on my form are submitted, and I only want this one field. There are a lot of fields on my form, and it's not necessary to submit all of them and then I have to deal with the validation of my form and so..

Is this possible in any way? Are is it something that can be added to the AjaxFormComponentUpdatingBehavior class?
Thanks ! Marieke

LightInTheBox - Buy quality products at wholesale price!