You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by j alex <st...@gmail.com> on 2007/08/07 13:50:13 UTC

S2 : XML vs annotation validation - thoughts?

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

Re: S2 : XML vs annotation validation - thoughts?

Posted by Ian Roughley <ia...@fdar.com>.
The validation and the related messages are on the domain objects and 
not the action, so they are separate.  Then the action defines which 
domain object is validated via the visitor validation - there is also a 
prefix (not sure of the exact attribute off hand), which would ensure 
that coapp or primaryapp is used to differentiate the domain objects.

/Ian

j alex wrote:
> Hi Ian,
>
> >From the documentation, VisitorFieldValidator seems interesting. Can you
> please provide some inputs on if/how we can use this for the following
> scenario :
>
> the domain object Name  has properties firstname, lastname, initial etc.
>
> now, Name could be associated with a primaryapplicant or a coapplicant
> object.
>
> In the JSP, we've s:text name="primaryapp.name.firstname" in the 1st page ;
> and s:text name="coapp.name.firstname" in the next page.
>
> How will i define a validation rule for the firstname field using
> annotations which can be used for validating both these fields ; without
> introducing any duplication. Also, i want to have the error message
> customized so that if primary's name is invalid ; the msg should be "please
> enter valid firstname for primary" and "please enter valid firstname for
> coapp" if coapp name has an error.
>
> I know this can be done easily in XML by having separate entries for primary
> and coapp and using params to manipulate the error message accordingly.
>
> Thanks,
> Joseph
>
> On 8/7/07, Ian Roughley <ia...@fdar.com> wrote:
>   
>> And you can place them on the domain objects and use a visitor validator
>> ;)
>>
>> Dave Newton wrote:
>>     
>>> --- j alex <st...@gmail.com> wrote:
>>>
>>>       
>>>> My understanding is that the validators are tied to
>>>> fields and not methods - right?
>>>>
>>>>         
>>> They *can* be tied to the fields (in other words,
>>> every action method) but you can specify validations
>>> based on the action name as well.
>>>
>>> d.
>>>
>>>
>>>
>>>
>>>
>>>       
>> ____________________________________________________________________________________
>>     
>>> Pinpoint customers who are looking for what you sell.
>>> http://searchmarketing.yahoo.com/
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>       
>
>   

Re: S2 : XML vs annotation validation - thoughts?

Posted by j alex <st...@gmail.com>.
Hi Ian,

>From the documentation, VisitorFieldValidator seems interesting. Can you
please provide some inputs on if/how we can use this for the following
scenario :

the domain object Name  has properties firstname, lastname, initial etc.

now, Name could be associated with a primaryapplicant or a coapplicant
object.

In the JSP, we've s:text name="primaryapp.name.firstname" in the 1st page ;
and s:text name="coapp.name.firstname" in the next page.

How will i define a validation rule for the firstname field using
annotations which can be used for validating both these fields ; without
introducing any duplication. Also, i want to have the error message
customized so that if primary's name is invalid ; the msg should be "please
enter valid firstname for primary" and "please enter valid firstname for
coapp" if coapp name has an error.

I know this can be done easily in XML by having separate entries for primary
and coapp and using params to manipulate the error message accordingly.

Thanks,
Joseph

On 8/7/07, Ian Roughley <ia...@fdar.com> wrote:
>
> And you can place them on the domain objects and use a visitor validator
> ;)
>
> Dave Newton wrote:
> > --- j alex <st...@gmail.com> wrote:
> >
> >> My understanding is that the validators are tied to
> >> fields and not methods - right?
> >>
> >
> > They *can* be tied to the fields (in other words,
> > every action method) but you can specify validations
> > based on the action name as well.
> >
> > d.
> >
> >
> >
> >
> >
> ____________________________________________________________________________________
> > Pinpoint customers who are looking for what you sell.
> > http://searchmarketing.yahoo.com/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

Re: S2 : XML vs annotation validation - thoughts?

Posted by Ian Roughley <ia...@fdar.com>.
And you can place them on the domain objects and use a visitor validator ;)

Dave Newton wrote:
> --- j alex <st...@gmail.com> wrote:
>   
>> My understanding is that the validators are tied to 
>> fields and not methods - right?
>>     
>
> They *can* be tied to the fields (in other words,
> every action method) but you can specify validations
> based on the action name as well.
>
> d.
>
>
>
>        
> ____________________________________________________________________________________
> Pinpoint customers who are looking for what you sell. 
> http://searchmarketing.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>   

Re: S2 : XML vs annotation validation - thoughts?

Posted by Dave Newton <ne...@yahoo.com>.
--- j alex <st...@gmail.com> wrote:
> My understanding is that the validators are tied to 
> fields and not methods - right?

They *can* be tied to the fields (in other words,
every action method) but you can specify validations
based on the action name as well.

d.



       
____________________________________________________________________________________
Pinpoint customers who are looking for what you sell. 
http://searchmarketing.yahoo.com/

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


Re: S2 : XML vs annotation validation - thoughts?

Posted by Kevin Lawrence <ke...@diamond-sky.com>.
Here's a better example that I just ran into:

I had getEmail() and getPassword() with @RequiredStringValidator on the 
base UserAction.

When I came to test ResetPasswordAction (which only requires an email), 
my execute() method was never called but I got no field errors on the 
rendered page.

After some head-scratching, I realized that getPassword was required 
(because it was inherited by the action) by the password was not set 
because it was not in the form.

I worked around it by pushing get/set password down into all of the 
actions that needed it (create/update/login) but removing it from the 
ones which did not.

Kevin

j alex wrote:
> Thanks for your inputs.
> 
> Kevin, can you please explain a bit more abt the "provide a new annotation
> to enable/disable particular validations for particular methods"  -- are you
> saying that for certain actions (aka methods, i presume) you don't want the
> fields to be validated, but the validation needs to be fired for certain
> other methods? . My understanding is that the validators are tied to fields
> and not methods - right?
> 
> Since XML validation is more documented, and is what we used in S1 - i think
> i may end up going ahead with it ; but wanted to try out if things can be
> done better using annotations so that we can see all in 1 file rather than
> looking up 2 or more files.
> 
> Specifically, i will need some custom validators that must act on a set of
> fields ; and the validation message must be customized based on the context
> in which the field is used - ex : "please enter primary applicant's first
> name" when firstname field is used in primaryapp and "please enter
> co-applicant's first name" when firstname is used in coapp instance. Does
> annotation provide enough flexibility to define resourcebundle key
> substitution in this way ; and is there a way we can substitute the right
> message using some kind of reflection to know which context the object is
> being used ?
> 
> Code examples for these will really help.
> 
> -Joseph
> 
> 
> 
> On 8/7/07, Kevin Lawrence <ke...@diamond-sky.com> wrote:
>> 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 <je...@blueskyminds.com.au> 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: 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: S2 : XML vs annotation validation - thoughts?

Posted by Kevin Lawrence <ke...@diamond-sky.com>.
I am a struts newbie so take my thoughts for what they are ... a newbie 
grappling with a new way of doing things. Maybe (I hope!) an expert will 
show me the error of my ways.

A simple example:

I wanted to put all the user properties on a UserAction that is shared 
by my 'create user' and 'update user' actions/methods but the property 
'I have read the terms and conditions' only applies to new users.

I also wanted to share the same base action for my Login, but login does 
not _require_ the same firstName, lastName etc that UpdateSettings requires.

Instead I chose to create separate actions for 'login' and 'update user' 
  with duplicate getters/setters - but different validation annotations 
- for user name and password.

For the update vs create user, I chose to move the isLegal validation 
into code:

     if(! legal) {
       addFieldError("legal", getText("user.legal.required"));
       return INPUT;
     }





My scenario could have been satisfied by having a single set of getters 
and getters (with annotations on the getters) if I had a way to say 
'this validation does not apply in this scenario'.

I guess I could have switched to xml validation but I have an 
instinctive aversion to separating the validation requirements from the 
code. I chose to live with the duplication.

It's a little frustrating because the annotation validation is so 
elegant and extensible - but not quite powerful enough to handle all the 
cases.

If I am missing something obvious, I'd love to hear it.

Kevin

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


j alex wrote:
> Thanks for your inputs.
> 
> Kevin, can you please explain a bit more abt the "provide a new annotation
> to enable/disable particular validations for particular methods"  -- are you
> saying that for certain actions (aka methods, i presume) you don't want the
> fields to be validated, but the validation needs to be fired for certain
> other methods? . My understanding is that the validators are tied to fields
> and not methods - right?
> 
> Since XML validation is more documented, and is what we used in S1 - i think
> i may end up going ahead with it ; but wanted to try out if things can be
> done better using annotations so that we can see all in 1 file rather than
> looking up 2 or more files.
> 
> Specifically, i will need some custom validators that must act on a set of
> fields ; and the validation message must be customized based on the context
> in which the field is used - ex : "please enter primary applicant's first
> name" when firstname field is used in primaryapp and "please enter
> co-applicant's first name" when firstname is used in coapp instance. Does
> annotation provide enough flexibility to define resourcebundle key
> substitution in this way ; and is there a way we can substitute the right
> message using some kind of reflection to know which context the object is
> being used ?
> 
> Code examples for these will really help.
> 
> -Joseph
> 
> 
> 
> On 8/7/07, Kevin Lawrence <ke...@diamond-sky.com> wrote:
>> 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 <je...@blueskyminds.com.au> 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: 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: S2 : XML vs annotation validation - thoughts?

Posted by j alex <st...@gmail.com>.
Thanks for your inputs.

Kevin, can you please explain a bit more abt the "provide a new annotation
to enable/disable particular validations for particular methods"  -- are you
saying that for certain actions (aka methods, i presume) you don't want the
fields to be validated, but the validation needs to be fired for certain
other methods? . My understanding is that the validators are tied to fields
and not methods - right?

Since XML validation is more documented, and is what we used in S1 - i think
i may end up going ahead with it ; but wanted to try out if things can be
done better using annotations so that we can see all in 1 file rather than
looking up 2 or more files.

Specifically, i will need some custom validators that must act on a set of
fields ; and the validation message must be customized based on the context
in which the field is used - ex : "please enter primary applicant's first
name" when firstname field is used in primaryapp and "please enter
co-applicant's first name" when firstname is used in coapp instance. Does
annotation provide enough flexibility to define resourcebundle key
substitution in this way ; and is there a way we can substitute the right
message using some kind of reflection to know which context the object is
being used ?

Code examples for these will really help.

-Joseph



On 8/7/07, Kevin Lawrence <ke...@diamond-sky.com> wrote:
>
> 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 <je...@blueskyminds.com.au> 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: 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: S2 : XML vs annotation validation - thoughts?

Posted by Kevin Lawrence <ke...@diamond-sky.com>.
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 <je...@blueskyminds.com.au> 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: 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: S2 : XML vs annotation validation - thoughts?

Posted by Musachy Barroso <mu...@gmail.com>.
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 <je...@blueskyminds.com.au> 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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Re: S2 : XML vs annotation validation - thoughts?

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org