You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jesse Foster <je...@verizonbusiness.com> on 2007/10/16 21:48:47 UTC

Disable form validation based on which submit button used?

Is there any way to enable/disable form validation based on which submit
button I use?  My page displays surveys, which are essentially rows of
radiogroups and corresponding radios displayed in table like fashion.  There
are two buttons on the page, one called "Finish" that saves all the answers
on the page and finalizes the survey so no further editing will occur.  The
other button is "Save and Exit" which just saves the current set of answers,
so even if a radiogroup has no answer I still want to update my model.  In
one case with "Finish" I want to validate all radiogroups have an answer by
using setRequired(true), while on the flip side with "Save and Exit" I don't
need that validation.

I thought of using setDefaultFormProcessing(false) on the "Save and Exit"
button and then manually populating the form model but Wicket ties model
populating to validation.  The updateModel() call in FormComponent simply
calls getConvertedInput() to populate the model object.  ConvertedInput is
assigned its value during validate().

Only solution I can think of is to subclass RadioGroup and override
updateModel() to convert the input and then set the model object.  If there
is a cleaner or better way to do this please let me know.
-- 
View this message in context: http://www.nabble.com/Disable-form-validation-based-on-which-submit-button-used--tf4636406.html#a13241117
Sent from the Wicket - User 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: Disable form validation based on which submit button used?

Posted by Jesse Foster <je...@verizonbusiness.com>.
Ok, found a way to do what I want.

Both buttons for my form do setDefaultFormProcessing(false)

I subclass Form and add a boolean attribute called bypassValidation with the
appropriate getters and setters.  I also override process() with my own
method that duplicates the original method, except the if clause is now if
(hasError() && bypassValidation==false)

In the OnSubmit() methods for my Buttons get the form and set the the
bypassValidation attribute.  Now I call process() and let the form update my
model.  Finally for the "Save and Exit" button I clear the FeedbackMessages
since it still gets populated with any validation errors. 

At this point the form and model are at the same state I would get from the
the normal validation process.


Jesse Foster wrote:
> 
> Two problems
> 1. updateFormComponentModels() is a protected method.
> 2. Without calling validate() first, updateFormComponentModels() updates
> the model with null values.  The actual process of taking values from the
> html form and converting them into Java objects happens inside validate()
> call.
> 
> 
> Bruno Borges wrote:
>> 
>> In each onSubmit button method, you call what you want, but don't forget
>> to
>> setDefaultFormProcessing(false) on them. This way, no validation is made
>> nor
>> models are updated. You have to control yourself inside onSubmit.
>> 
>> Call form.updateFormComponentModels();      (something like that)
>> To "Save & Exit"
>> 
>> And for the Finish button,  call validate(); and _after_ the
>> updateFormComponentModels...
>> 
>> I think this is it. :)
>> 
>> give  it a shot
>> 
>> 
>> 
>> On 10/16/07, Jesse Foster <je...@verizonbusiness.com> wrote:
>>>
>>>
>>> Is there any way to enable/disable form validation based on which submit
>>> button I use?  My page displays surveys, which are essentially rows of
>>> radiogroups and corresponding radios displayed in table like
>>> fashion.  There
>>> are two buttons on the page, one called "Finish" that saves all the
>>> answers
>>> on the page and finalizes the survey so no further editing will
>>> occur.  The
>>> other button is "Save and Exit" which just saves the current set of
>>> answers,
>>> so even if a radiogroup has no answer I still want to update my model. 
>>> In
>>> one case with "Finish" I want to validate all radiogroups have an answer
>>> by
>>> using setRequired(true), while on the flip side with "Save and Exit" I
>>> don't
>>> need that validation.
>>>
>>> I thought of using setDefaultFormProcessing(false) on the "Save and
>>> Exit"
>>> button and then manually populating the form model but Wicket ties model
>>> populating to validation.  The updateModel() call in FormComponent
>>> simply
>>> calls getConvertedInput() to populate the model object.  ConvertedInput
>>> is
>>> assigned its value during validate().
>>>
>>> Only solution I can think of is to subclass RadioGroup and override
>>> updateModel() to convert the input and then set the model object.  If
>>> there
>>> is a cleaner or better way to do this please let me know.
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Disable-form-validation-based-on-which-submit-button-used--tf4636406.html#a13241117
>>> Sent from the Wicket - User 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
>>>
>>>
>> 
>> 
>> -- 
>> Bruno Borges
>> Summa Technologies
>> www.summa-tech.com
>> 55 11 85657739  /  55 11 30552054
>> 
>> "The glory of great men should always be
>> measured by the means they have used to
>> acquire it."
>> - Francois de La Rochefoucauld
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Disable-form-validation-based-on-which-submit-button-used--tf4636406.html#a13244641
Sent from the Wicket - User 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: Disable form validation based on which submit button used?

Posted by Jesse Foster <je...@verizonbusiness.com>.
Two problems
1. updateFormComponentModels() is a protected method.
2. Without calling validate() first, updateFormComponentModels() updates the
model with null values.  The actual process of taking values from the html
form and converting them into Java objects happens inside validate() call.


Bruno Borges wrote:
> 
> In each onSubmit button method, you call what you want, but don't forget
> to
> setDefaultFormProcessing(false) on them. This way, no validation is made
> nor
> models are updated. You have to control yourself inside onSubmit.
> 
> Call form.updateFormComponentModels();      (something like that)
> To "Save & Exit"
> 
> And for the Finish button,  call validate(); and _after_ the
> updateFormComponentModels...
> 
> I think this is it. :)
> 
> give  it a shot
> 
> 
> 
> On 10/16/07, Jesse Foster <je...@verizonbusiness.com> wrote:
>>
>>
>> Is there any way to enable/disable form validation based on which submit
>> button I use?  My page displays surveys, which are essentially rows of
>> radiogroups and corresponding radios displayed in table like
>> fashion.  There
>> are two buttons on the page, one called "Finish" that saves all the
>> answers
>> on the page and finalizes the survey so no further editing will
>> occur.  The
>> other button is "Save and Exit" which just saves the current set of
>> answers,
>> so even if a radiogroup has no answer I still want to update my model. 
>> In
>> one case with "Finish" I want to validate all radiogroups have an answer
>> by
>> using setRequired(true), while on the flip side with "Save and Exit" I
>> don't
>> need that validation.
>>
>> I thought of using setDefaultFormProcessing(false) on the "Save and Exit"
>> button and then manually populating the form model but Wicket ties model
>> populating to validation.  The updateModel() call in FormComponent simply
>> calls getConvertedInput() to populate the model object.  ConvertedInput
>> is
>> assigned its value during validate().
>>
>> Only solution I can think of is to subclass RadioGroup and override
>> updateModel() to convert the input and then set the model object.  If
>> there
>> is a cleaner or better way to do this please let me know.
>> --
>> View this message in context:
>> http://www.nabble.com/Disable-form-validation-based-on-which-submit-button-used--tf4636406.html#a13241117
>> Sent from the Wicket - User 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
>>
>>
> 
> 
> -- 
> Bruno Borges
> Summa Technologies
> www.summa-tech.com
> 55 11 85657739  /  55 11 30552054
> 
> "The glory of great men should always be
> measured by the means they have used to
> acquire it."
> - Francois de La Rochefoucauld
> 
> 

-- 
View this message in context: http://www.nabble.com/Disable-form-validation-based-on-which-submit-button-used--tf4636406.html#a13243863
Sent from the Wicket - User 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: Disable form validation based on which submit button used?

Posted by Bruno Borges <br...@gmail.com>.
In each onSubmit button method, you call what you want, but don't forget to
setDefaultFormProcessing(false) on them. This way, no validation is made nor
models are updated. You have to control yourself inside onSubmit.

Call form.updateFormComponentModels();      (something like that)
To "Save & Exit"

And for the Finish button,  call validate(); and _after_ the
updateFormComponentModels...

I think this is it. :)

give  it a shot



On 10/16/07, Jesse Foster <je...@verizonbusiness.com> wrote:
>
>
> Is there any way to enable/disable form validation based on which submit
> button I use?  My page displays surveys, which are essentially rows of
> radiogroups and corresponding radios displayed in table like
> fashion.  There
> are two buttons on the page, one called "Finish" that saves all the
> answers
> on the page and finalizes the survey so no further editing will
> occur.  The
> other button is "Save and Exit" which just saves the current set of
> answers,
> so even if a radiogroup has no answer I still want to update my model.  In
> one case with "Finish" I want to validate all radiogroups have an answer
> by
> using setRequired(true), while on the flip side with "Save and Exit" I
> don't
> need that validation.
>
> I thought of using setDefaultFormProcessing(false) on the "Save and Exit"
> button and then manually populating the form model but Wicket ties model
> populating to validation.  The updateModel() call in FormComponent simply
> calls getConvertedInput() to populate the model object.  ConvertedInput is
> assigned its value during validate().
>
> Only solution I can think of is to subclass RadioGroup and override
> updateModel() to convert the input and then set the model object.  If
> there
> is a cleaner or better way to do this please let me know.
> --
> View this message in context:
> http://www.nabble.com/Disable-form-validation-based-on-which-submit-button-used--tf4636406.html#a13241117
> Sent from the Wicket - User 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
>
>


-- 
Bruno Borges
Summa Technologies
www.summa-tech.com
55 11 85657739  /  55 11 30552054

"The glory of great men should always be
measured by the means they have used to
acquire it."
- Francois de La Rochefoucauld