I started with annotations and wild-carded actions and I very quickly ran into the problem of not all fields apply to every action.

I briefly considered switching to xml validations but decided instead to stick with one method per action. I hated the duplicate code in the actions and in struts.xml less than I hated xml validations.

I really like the idea of validation annotations but there is something not quite flexible enough in the current design to support what I wanted to do. I tried to think of a design that would better support my needs but the best I could come up with is:

- keep the annotations on individual fields but
- provide a new annotation to enable/disable particular validations for particular methods


Kevin

www.junitfactory.com
You send us code. We send back tests. For free.


Musachy Barroso wrote:
On my current project I started using annotations, but very soon my
few actions were packed with them, to the point that I had more
annotations that actual code in my actions :), so I went the xml way.

musachy

On 8/7/07, Jeromy Evans <[EMAIL PROTECTED]> wrote:
Hi Joseph,

I haven't used annotation validation since S2.0.6 so these issues may be
a little dated.

These are my experiences:
1. I tend to use wildcards in actions.  In this situation, annotations
applied to properties in an action are not appropriate as not all
validations apply for each action method.  The alternative is to apply
the annotations to the action methods themselves but this approach
quickly become unwieldy (eg. 10 lines of annotations for each action
method).  I found multiple XML files (one for each action method/alias)
are far superior in this case.
2. the XML approach is better documented due to its longer history with WW.
3. In 2.0.6, annotations on multiple methods did not actually work as
implied in the documentation.  All annotated validators were applied
irrespective of which action method was being called.  This may have
been fixed but it was a show-stopper for us.
4. Both approaches share the disadvantage that it's easy to mistype
field names.  Annoyingly the annotation doesn't help as you need to
hand-type each fieldName when its applied to an action method. The
benefit of annotations is lost.

If you choose to use only a single method in each action (eg. execute())
then the annotation validation works well as shown on the wiki.

Hope that helps you make a decision.

Jeromy Evans

j alex wrote:
Hi,

I am about to migrate a S1 app to S2 and need to decide which route to take
regarding validations - XML or annotations? . Our app has a lot of custom
validators involving rules dependent on multiple fields. Is there a specific
benefit to using annotations vs XML ?

Thanks,
Joseph


------------------------------------------------------------------------

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.476 / Virus Database: 269.11.8/940 - Release Date: 6/08/2007 4:53 
PM


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to