You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Anil Kumar T <an...@infics.com> on 2006/09/14 08:26:44 UTC

Using ValidatorFramework for different validation scenarios of same functioanlity/form.

Hi Group,



I need a help on general issue which every body would have solved.



Generally we'll have four operations like Add, Update, Query and Remove.
I believe we can use DispatchAction to handle all these operation in a
single action. So for the validation part we are planning to use
validator framework. Generally for create we will need to validate all
the mandatory fields (not the PK value incase of DB sequence) and for
update all the fields including the PK fields(as hidden fields) and for
query there may not be any validations and for delete operation we need
to validate the PK value alone. I'm not sure whether we can achieve this
kind of validation using validator framework or not. Because from my
understanding I believe that validator framework would be invoked first
and then the Action class. So can we validate the fields on conditional
basis?



I think we can do this by writing each operation in different action
calss.



Or is there a better approach for this kind of scenarios. Any help,
information, links material would be helpful.



If my question is not clear, let me know.



Thanks & regards,

Anil.



Information transmitted by this e-mail is proprietary to Infinite Computer Solutions and / or its Customers and is intended for use only by the individual or the entity to which it is addressed, and may contain information that is privileged, confidential or exempt from disclosure under applicable law. If you are not the intended recipient or it appears that this mail has been forwarded to you without proper authority, you are notified that any use or dissemination of this information in any manner is strictly prohibited. In such cases, please notify us immediately at info.in@infics.com and delete this email from your records.

Re: Using ValidatorFramework for different validation scenarios of same functioanlity/form.

Posted by Laurie Harper <la...@holoweb.net>.
Anil Kumar T wrote:
> Hi Group,
> 
> I need a help on general issue which every body would have solved.
> 
> Generally we'll have four operations like Add, Update, Query and Remove.
> I believe we can use DispatchAction to handle all these operation in a
> single action. So for the validation part we are planning to use
> validator framework. Generally for create we will need to validate all
> the mandatory fields (not the PK value incase of DB sequence) and for
> update all the fields including the PK fields(as hidden fields) and for
> query there may not be any validations and for delete operation we need
> to validate the PK value alone. I'm not sure whether we can achieve this
> kind of validation using validator framework or not. Because from my
> understanding I believe that validator framework would be invoked first
> and then the Action class. So can we validate the fields on conditional
> basis?
> 
> I think we can do this by writing each operation in different action
> calss.
> 
> Or is there a better approach for this kind of scenarios. Any help,
> information, links material would be helpful.

There are a few options here. The simplest may be to call validation 
manually (set validate="false" in your action mapping, and call 
form.validate() somewhere in your action's execute() method). That gives 
you the most control.

Alternatively, the validation framework has support for 'multiple page 
validations' designed for wizard-type workflows. You could use that to 
select a set of validations based on which action was being performed 
(treating different actions like different pages in a workflow).

Another option may be to use validwhen validation rules, but since 
there's no easy way to conditionally invoke other rules (like required, 
integer, etc.) from a validwhen rule, this approach would probably get 
pretty messy...

If you have different action mappings for each operation, there's an 
easier option though: in that case, you can map your validation rule 
sets using the action mapping path instead of the form name -- in other 
words, apply different validation rules for /addFoo, /updateFoo, 
/queryFoo and /removeFoo whilst using the same form bean for each. To do 
that, you need to subclass ValidatorActionForm instead of ValidatorForm.

L.



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