You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mi...@edgil.com on 2004/04/15 22:40:47 UTC

Validator vs form Validate() method.

Hi folks,

I've gotten myself sorely confused here...

I've set up the validator to do simple validation on my forms.  By "simple
validation" I mean checking for required fields and integer input, etc.

I need to use the validate() method to do more complex validation on one
form, I need to verify that a date the user enters is in the future.

The problem is that it seems that as soon as I implement the validate()
method in my form, it seems to bypass the validator, all those checks are
no longer done.  If I comment out validate(), the validator starts working
again.  (Note:  This is the behavior I see whether or not the validation in
validate() passes or fails)

Have I got something configured incorrectly, or is this the way its
intended to work?

Thanx!

c'ya
Mike
----
Mike Boucher                  mboucher@edgil.com
Edgil Associates              www.edgil.com

"Don't take life too seriously, you'll never get out of it alive!"


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


Re: Validator vs form Validate() method.

Posted by Nathan Maves <Na...@Sun.COM>.
Here is the solution I think....

In section 12.10.5 of Struts in Action by Ted Husted


There is an example of how to combine validator with the validate 
method.

try this code

public ActionErrors validate(.....) {
   ActionErrors errors = super.validate(mapping, request);
   if(errors == null) errors = new ActionErrors();

   ....Continue with your custom validation...
}


Let me know if that works.

Nathan

On Apr 15, 2004, at 3:45 PM, Nathan Maves wrote:

> Ahh after a little research I think I might have answered that wrong.
>
> What is your action form extending?
>
> Nathan
>
> On Apr 15, 2004, at 3:37 PM, Nathan Maves wrote:
>
>> I am just a newB but couldn't you call the validate method from your 
>> execute method.  This way the validator will catch any of the easy 
>> validations and your validate method will get the complex ones.
>>
>> Again just a newB answer.
>>
>> Nathan
>>
>>
>> On Apr 15, 2004, at 2:40 PM, MichaelBoucher@edgil.com wrote:
>>
>>> Hi folks,
>>>
>>> I've gotten myself sorely confused here...
>>>
>>> I've set up the validator to do simple validation on my forms.  By 
>>> "simple
>>> validation" I mean checking for required fields and integer input, 
>>> etc.
>>>
>>> I need to use the validate() method to do more complex validation on 
>>> one
>>> form, I need to verify that a date the user enters is in the future.
>>>
>>> The problem is that it seems that as soon as I implement the 
>>> validate()
>>> method in my form, it seems to bypass the validator, all those 
>>> checks are
>>> no longer done.  If I comment out validate(), the validator starts 
>>> working
>>> again.  (Note:  This is the behavior I see whether or not the 
>>> validation in
>>> validate() passes or fails)
>>>
>>> Have I got something configured incorrectly, or is this the way its
>>> intended to work?
>>>
>>> Thanx!
>>>
>>> c'ya
>>> Mike
>>> ----
>>> Mike Boucher                  mboucher@edgil.com
>>> Edgil Associates              www.edgil.com
>>>
>>> "Don't take life too seriously, you'll never get out of it alive!"
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>
>
> ---------------------------------------------------------------------
> 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: Validator vs form Validate() method.

Posted by Nathan Maves <Na...@Sun.COM>.
Ahh after a little research I think I might have answered that wrong.

What is your action form extending?

Nathan

On Apr 15, 2004, at 3:37 PM, Nathan Maves wrote:

> I am just a newB but couldn't you call the validate method from your 
> execute method.  This way the validator will catch any of the easy 
> validations and your validate method will get the complex ones.
>
> Again just a newB answer.
>
> Nathan
>
>
> On Apr 15, 2004, at 2:40 PM, MichaelBoucher@edgil.com wrote:
>
>> Hi folks,
>>
>> I've gotten myself sorely confused here...
>>
>> I've set up the validator to do simple validation on my forms.  By 
>> "simple
>> validation" I mean checking for required fields and integer input, 
>> etc.
>>
>> I need to use the validate() method to do more complex validation on 
>> one
>> form, I need to verify that a date the user enters is in the future.
>>
>> The problem is that it seems that as soon as I implement the 
>> validate()
>> method in my form, it seems to bypass the validator, all those checks 
>> are
>> no longer done.  If I comment out validate(), the validator starts 
>> working
>> again.  (Note:  This is the behavior I see whether or not the 
>> validation in
>> validate() passes or fails)
>>
>> Have I got something configured incorrectly, or is this the way its
>> intended to work?
>>
>> Thanx!
>>
>> c'ya
>> Mike
>> ----
>> Mike Boucher                  mboucher@edgil.com
>> Edgil Associates              www.edgil.com
>>
>> "Don't take life too seriously, you'll never get out of it alive!"
>>
>>
>> ---------------------------------------------------------------------
>> 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
>


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


Re: Validator vs form Validate() method.

Posted by Craig McClanahan <cr...@apache.org>.
Nathan Maves wrote:

> I am just a newB but couldn't you call the validate method from your 
> execute method.  This way the validator will catch any of the easy 
> validations and your validate method will get the complex ones.
>
Are you remembering to call super.validate() somewhere in your 
validate() method's implementation?  You probably want to do that at the 
beginning, so that it will perform all the "simple" validations that are 
defined by your validator framework rules (which is embedded in the 
validate() method of the standard form bean class); then, if no errors 
have been encountered, you can hard code the more complex validations.

Craig


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


Re: Validator vs form Validate() method.

Posted by Nathan Maves <Na...@Sun.COM>.
I am just a newB but couldn't you call the validate method from your 
execute method.  This way the validator will catch any of the easy 
validations and your validate method will get the complex ones.

Again just a newB answer.

Nathan


On Apr 15, 2004, at 2:40 PM, MichaelBoucher@edgil.com wrote:

> Hi folks,
>
> I've gotten myself sorely confused here...
>
> I've set up the validator to do simple validation on my forms.  By 
> "simple
> validation" I mean checking for required fields and integer input, etc.
>
> I need to use the validate() method to do more complex validation on 
> one
> form, I need to verify that a date the user enters is in the future.
>
> The problem is that it seems that as soon as I implement the validate()
> method in my form, it seems to bypass the validator, all those checks 
> are
> no longer done.  If I comment out validate(), the validator starts 
> working
> again.  (Note:  This is the behavior I see whether or not the 
> validation in
> validate() passes or fails)
>
> Have I got something configured incorrectly, or is this the way its
> intended to work?
>
> Thanx!
>
> c'ya
> Mike
> ----
> Mike Boucher                  mboucher@edgil.com
> Edgil Associates              www.edgil.com
>
> "Don't take life too seriously, you'll never get out of it alive!"
>
>
> ---------------------------------------------------------------------
> 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