You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Marek Pribyl <mr...@gmail.com> on 2011/01/05 13:19:48 UTC

one form - two submit buttons with different behavior

hi all,
I have form with two submit buttons & want different behavior for each
button.

submitButton:
- standard submit button
- expected "onClick" behavior: validate form & save the form's model
(implemented in form's onSubmit() method) & redirect to another page

ajaxButton:
- AjaxButton
- expected "onClick" behavior: validate form, if valid get form's model
& display it as XML in modal window for preview

the problem is that form's onSubmit() is called when I click on
ajaxButton - I need to keep validation but do not call form's onSubmit()
method, i.e. stay on the current form page & do not save the model.
Is there any chance to do this wicket way?

thanks,
marek


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


Re: one form - two submit buttons with different behavior

Posted by Martin Grigorov <mg...@apache.org>.
An idea:

in Form#onSubmit() check whether the current request is Ajax: if
(AjaxRequestTarget.get() != null) return; // i.e. do not execute the method'
body

You can even check whether the submittingComponent is the AjaxButton and do
nothing in that case only

On Wed, Jan 5, 2011 at 1:19 PM, Marek Pribyl <mr...@gmail.com> wrote:

> hi all,
> I have form with two submit buttons & want different behavior for each
> button.
>
> submitButton:
> - standard submit button
> - expected "onClick" behavior: validate form & save the form's model
> (implemented in form's onSubmit() method) & redirect to another page
>
> ajaxButton:
> - AjaxButton
> - expected "onClick" behavior: validate form, if valid get form's model
> & display it as XML in modal window for preview
>
> the problem is that form's onSubmit() is called when I click on
> ajaxButton - I need to keep validation but do not call form's onSubmit()
> method, i.e. stay on the current form page & do not save the model.
> Is there any chance to do this wicket way?
>
> thanks,
> marek
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: one form - two submit buttons with different behavior

Posted by Marek Pribyl <mr...@gmail.com>.
thanks all for reply, I chose martin's solution which works for me in
this particular case

marek

On Wed, 2011-01-05 at 13:19 +0100, Marek Pribyl wrote:
> hi all,
> I have form with two submit buttons & want different behavior for each
> button.
> 
> submitButton:
> - standard submit button
> - expected "onClick" behavior: validate form & save the form's model
> (implemented in form's onSubmit() method) & redirect to another page
> 
> ajaxButton:
> - AjaxButton
> - expected "onClick" behavior: validate form, if valid get form's model
> & display it as XML in modal window for preview
> 
> the problem is that form's onSubmit() is called when I click on
> ajaxButton - I need to keep validation but do not call form's onSubmit()
> method, i.e. stay on the current form page & do not save the model.
> Is there any chance to do this wicket way?
> 
> thanks,
> marek




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


Re: one form - two submit buttons with different behavior

Posted by andrea del bene <an...@libero.it>.
Hi  Marek,

you could override form method  'process(IFormSubmittingComponent 
submittingComponent) ' checking whether submittingComponent is 
submitButton or ajaxButton. submitButton follows standard behavior 
calling super.process(...),  whereas ajaxButton just call validate().
But remember that form's onSubmit() must be called anyway, so as Pedro 
suggested you should move onSubmit code to submitButton.


> hi all,
> I have form with two submit buttons&  want different behavior for each
> button.
>
> submitButton:
> - standard submit button
> - expected "onClick" behavior: validate form&  save the form's model
> (implemented in form's onSubmit() method)&  redirect to another page
>
> ajaxButton:
> - AjaxButton
> - expected "onClick" behavior: validate form, if valid get form's model
> &  display it as XML in modal window for preview
>
> the problem is that form's onSubmit() is called when I click on
> ajaxButton - I need to keep validation but do not call form's onSubmit()
> method, i.e. stay on the current form page&  do not save the model.
> Is there any chance to do this wicket way?
>
> thanks,
> marek
>
>
> ---------------------------------------------------------------------
> 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: one form - two submit buttons with different behavior

Posted by Pedro Santos <pe...@gmail.com>.
You can also move all your code from form.onSubmit to the
standartButton.onSubmit

On Wed, Jan 5, 2011 at 10:19 AM, Marek Pribyl <mr...@gmail.com> wrote:

> hi all,
> I have form with two submit buttons & want different behavior for each
> button.
>
> submitButton:
> - standard submit button
> - expected "onClick" behavior: validate form & save the form's model
> (implemented in form's onSubmit() method) & redirect to another page
>
> ajaxButton:
> - AjaxButton
> - expected "onClick" behavior: validate form, if valid get form's model
> & display it as XML in modal window for preview
>
> the problem is that form's onSubmit() is called when I click on
> ajaxButton - I need to keep validation but do not call form's onSubmit()
> method, i.e. stay on the current form page & do not save the model.
> Is there any chance to do this wicket way?
>
> thanks,
> marek
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Pedro Henrique Oliveira dos Santos