You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Laurie Harper <la...@holoweb.net> on 2007/10/11 00:28:13 UTC

Re: Adding the ability to include a validation xml file from another inside another validation xml file in Struts2

I thought you could also specify validation rules against model classes 
as well, which might help if the rules that are repeated are always the 
same for a particular model property; I can't find mention of that 
capability in the validation docs off-hand, though.

You may also be able to leverage inheritance here; if you can give the 
set of actions that need to share/duplicate validation rules a common 
base class, you can specify those rules in BaseClass-validation.xml and 
the sub-classes should pick them up.

And if all else fails, there's always good old XML external entities. 
You'd have to repeat the definition of the external entities at the head 
of each *-validation.xml, but that's a lot less duplication than 
repeating the actual rules.

L.

Ian Roughley wrote:
> Have you looked at the visitor validator?  It might serve your purposes 
> if the fields are on objects in the action.
> 
> /Ian
> 
> Arup Francis wrote:
>> Hi,
>>
>>    We have this problem of having to repeat certain validations for 
>> the same
>> fields in multiple validation xml files because they occur in multiple
>> scenarios and we have different validation files for the different
>> scenarios. Now this brings about duplication of code in the sense that in
>> future if I need to modify the validation for the fields then I have 
>> to do
>> it in multiple files which is quite a pain. I was thinking that if it was
>> possible to have the ability to include one validation file within 
>> another
>> validation xml then it would help us in removing the duplication of code
>> because I could define the validation for the fields in a single file and
>> then include that file in the multiple scenario validation files.
>>
>> Its something like the <s:include /> that you have for the struts.xml 
>> using
>> which you can include other struts configuration files.
>>
>> Struts 2 gurus - Please let me know on what you feel about this.
>> Maybe this can be added as an enhancement in future versions of struts2.
>>
>> Arup
>>   


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


Re: Adding the ability to include a validation xml file from another inside another validation xml file in Struts2

Posted by Arup Francis <ar...@bankofamerica.com>.
Hi Laurie,

   The visitor validator is I believe the same thing (or almost similar) as
specifying validation rules against model classes. I was able to fix my
problem of duplication using that.

The BaseClass implementation will not work because I looked up the way the
validation xml's associated with a particular action is determined in the
validator interceptor and its based on the action name i.e. if SubBaseAction
is the action name then the interceptor will try to find out if any
validation xml's exist of the format SubBaseAction-*-validation.xml and so
it won't work if we have a validation file called
BaseAction-*-validation.xml. 

Arup



Laurie Harper wrote:
> 
> I thought you could also specify validation rules against model classes 
> as well, which might help if the rules that are repeated are always the 
> same for a particular model property; I can't find mention of that 
> capability in the validation docs off-hand, though.
> 
> You may also be able to leverage inheritance here; if you can give the 
> set of actions that need to share/duplicate validation rules a common 
> base class, you can specify those rules in BaseClass-validation.xml and 
> the sub-classes should pick them up.
> 
> And if all else fails, there's always good old XML external entities. 
> You'd have to repeat the definition of the external entities at the head 
> of each *-validation.xml, but that's a lot less duplication than 
> repeating the actual rules.
> 
> L.
> 
> Ian Roughley wrote:
>> Have you looked at the visitor validator?  It might serve your purposes 
>> if the fields are on objects in the action.
>> 
>> /Ian
>> 
>> Arup Francis wrote:
>>> Hi,
>>>
>>>    We have this problem of having to repeat certain validations for 
>>> the same
>>> fields in multiple validation xml files because they occur in multiple
>>> scenarios and we have different validation files for the different
>>> scenarios. Now this brings about duplication of code in the sense that
>>> in
>>> future if I need to modify the validation for the fields then I have 
>>> to do
>>> it in multiple files which is quite a pain. I was thinking that if it
>>> was
>>> possible to have the ability to include one validation file within 
>>> another
>>> validation xml then it would help us in removing the duplication of code
>>> because I could define the validation for the fields in a single file
>>> and
>>> then include that file in the multiple scenario validation files.
>>>
>>> Its something like the <s:include /> that you have for the struts.xml 
>>> using
>>> which you can include other struts configuration files.
>>>
>>> Struts 2 gurus - Please let me know on what you feel about this.
>>> Maybe this can be added as an enhancement in future versions of struts2.
>>>
>>> Arup
>>>   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Adding-the-ability-to-include-a-validation-xml-file-from-inside-another-validation-xml-file-in-Struts2-tf4601659.html#a13154572
Sent from the Struts - User mailing list archive at Nabble.com.


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