You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jennifer Jacobs <ja...@firstenergycorp.com> on 2006/06/26 20:42:38 UTC

Validate just certain fields

I'm using the Struts Validator framework.

I have a form with two buttons on it, one that calculates a subtotal and one
that submits the form.  I have validation set to false, because I don't want
to validate the shipping address/email/phone number/etc when they calculate
the subtotal.  So, I do a form.validate() when the submit button is hit.

However, I DO want to validate the values they put in for quantity, etc.  I
know I can write validation for it all, but then my validation is in two
places - is there any way to "tell" it to validate JUST a certain set of
fields?

Thanks in advance,
Jennifer
--
View this message in context: http://www.nabble.com/Validate-just-certain-fields-t1850707.html#a5052596
Sent from the Struts - User forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Validate just certain fields

Posted by Jennifer Jacobs <ja...@firstenergycorp.com>.
Jasper,

Thank you for your response.  I'm not sure you understand my issue, though. 
Either that, or I didn't understand your response, which is quite likely, as
I'm no old pro at this validation stuff.

The form has working validation on all the fields that require validation,
using the validation framework.  Let's say the form has 10 fields and 7 of
them need validated for whatever reason.  There's also two buttons on the
form: ButtonA and ButtonB.  ButtonA submits the form to our backend system. 
When ButtonA is hit, the 7 fields are validated and everything is working
perfectly.  ButtonB does NOT submit the form, it just does a simple
calculation.  However, because it needs to use 2 of the fields in order to
do that calculation, it needs to validate those two fields (that are part of
the 7).  Because it does NOT need to validate the other 5 fields, I can't do
validation on the whole form (or at least, don't want to).

I know I can programmatically do validation on the 2 fields, but that means
I have validation in two separate places - one in my validation framework,
and one in my code.  For instance, one of the fields is an integer that
can't be higher than 5.  What if that changes to 10 one day?  I have to
change it in two places, and I don't want to do that.  Is it possible for me
to make it use the validation I have set up in the validation.xml file for
only 2 of the 7 fields?
-- 
View this message in context: http://www.nabble.com/Validate-just-certain-fields-tf1850707.html#a5066921
Sent from the Struts - User forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Validate just certain fields

Posted by The Jasper <th...@gmail.com>.
HI,

You can write your own validate function or you can use the validation
framework. In any case no validation is performed on any field unless
you specify it. see
http://struts.apache.org/struts-action/faqs/validator.html for further
details.

mvg,
Jasper

On 6/26/06, Jennifer Jacobs <ja...@firstenergycorp.com> wrote:
>
> I'm using the Struts Validator framework.
>
> I have a form with two buttons on it, one that calculates a subtotal and one
> that submits the form.  I have validation set to false, because I don't want
> to validate the shipping address/email/phone number/etc when they calculate
> the subtotal.  So, I do a form.validate() when the submit button is hit.
>
> However, I DO want to validate the values they put in for quantity, etc.  I
> know I can write validation for it all, but then my validation is in two
> places - is there any way to "tell" it to validate JUST a certain set of
> fields?
>
> Thanks in advance,
> Jennifer
> --
> View this message in context: http://www.nabble.com/Validate-just-certain-fields-t1850707.html#a5052596
> Sent from the Struts - User forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Validate just certain fields

Posted by Ed Griebel <ed...@gmail.com>.
You can use the "page" attribute on the validations, with the "page"
attribute. Look at
http://struts.apache.org/struts-doc-1.2.9/userGuide/dev_validator.html
under "Multi page forms" for an extremely brief overview.

Basically,  create a java.lang.Integer variable in your form called
"page" and before you call form.validate() set this page variable
appropriately: if subtotal was pressed set page=1, if submit then
page=2.

Define validations common to both in validations with page=1, and
submit only with page=2 in validation.xml:
<form name="SomeForm">
  <field property="quantity" page="1" depends="required"> ... </field>
  <field property="address" page="2" depends="required">...</field>
  ...
</form>

It's not the most elegant, but it does work well when you have a
linear page flow.

-ed

On 6/26/06, Jennifer Jacobs <ja...@firstenergycorp.com> wrote:
>
> I'm using the Struts Validator framework.
>
> I have a form with two buttons on it, one that calculates a subtotal and one
> that submits the form.  I have validation set to false, because I don't want
> to validate the shipping address/email/phone number/etc when they calculate
> the subtotal.  So, I do a form.validate() when the submit button is hit.
>
> However, I DO want to validate the values they put in for quantity, etc.  I
> know I can write validation for it all, but then my validation is in two
> places - is there any way to "tell" it to validate JUST a certain set of
> fields?
>
> Thanks in advance,
> Jennifer
> --
> View this message in context: http://www.nabble.com/Validate-just-certain-fields-t1850707.html#a5052596
> Sent from the Struts - User forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org