You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@bval.apache.org by Umesh Awasthi <um...@gmail.com> on 2013/10/15 18:48:25 UTC

bean validation using XML

I am trying to test bean validation for my plugin using XML based
configuration and while doing i found that i need to place validation/xml
file under

META-INF/validation.xml inside my resource folder.
For me this seems a little strange and who so ever want to use plugin needs
to create META-INF folder inside resource folder.

I am not sure, if my understanding is correct here and in case i am right,
is there any specific reason to choose XML location like this? or can we
customize this location

-- 
With Regards
Umesh Awasthi
http://www.travellingrants.com/

Re: bean validation using XML

Posted by Matt Benson <gu...@gmail.com>.
If it's not possible with basic Struts 2, you might define a SPI,
e.g. umesh.struts2plugin.ValidatorFactoryProvider, for your users to have
some ability to provide a ValidatorFactory in case they are doing something
unusual and can't just use the default instance.  If no custom
ValidatorFactoryProvider is found at runtime, then you can fall back to the
default.

Matt


On Tue, Oct 15, 2013 at 12:42 PM, Umesh Awasthi <um...@gmail.com>wrote:

> Hi Maat,
>
> By ValidatorFactory, you mean to let user create it as per his choice and
> let pass it on to plugin?
> if that is the case, i do not think it will be possible with current
> Struts2.
>
> Plugin in Struts2 will be initiated when framework will be loaded and
> there will be set of interceptors which are actually responsible to call
> validate method of BV.
>
> these interceptors will be called on each request (though they will not be
> created on each request) and user action can only be there once
> interceptors will be called without any error/ exceptions.
>
> Validation.buildDefaultValidatorFactory() is a good option and i add it to
> flow.
>
> Thanks
> Umesh
>
>
> On Tue, Oct 15, 2013 at 11:00 PM, Matt Benson <gu...@gmail.com>wrote:
>
>> I would recommend you allow your user to be a "real" Bean Validation
>> consumer and force them to bootstrap it in a normal way.  You can't predict
>> what other technologies they'll be using in conjunction with Struts 2, so
>> why try?  If you can write your plugin such that it can either be
>> configured with a ValidatorFactory instance or obtain one using
>> javax.validation.Validation.buildDefaultValidatorFactory(), then you would
>> seem to be covered, and you haven't insulated your user from the
>> responsbility/opportunity of learning how to set up BV metadata in whatever
>> manner makes sense for his particular scenario, including making his
>> preferred implementation available.  If, for example, the user is running
>> in a Java EE 6 or Java EE 6 Web Profile container, he would already have
>> some Bean Validation implementation available.  Otherwise, he'll have to
>> choose, but that's better IMO than your plugin providing things that may
>> not be needed, or worse, potentially causing unanticipated issues by
>> having, e.g., multiple versions of Apache BVal on the classpath.
>>
>> Matt
>>
>>
>> On Tue, Oct 15, 2013 at 12:15 PM, Umesh Awasthi <um...@gmail.com>wrote:
>>
>>> Hi Matt,
>>>
>>> Thanks for your inputs and agree with you, i do not want to bind my
>>> implementation with specific implementation.
>>> not sure if i am able to understand second part of your question
>>> completely.
>>> I am trying to provide a bridge between Struts2 and Bean validation
>>> API.While user submit there inputs, i am putting them through Validation
>>> using BV and if any kind of exception occurring, using Struts2 message API
>>> to read error messages and display them to UI.
>>>
>>> Through this , idea is to let use specify which bean validation they
>>> want to use be it
>>> 1. Apache Bean validation
>>> 2. Hibernate Validator.
>>>
>>> I have plan to put Apache Bean Validation as Default validator in case
>>> use do not specify any preferences and want to use out of box functionality.
>>>
>>> Validation.byProvider(this.providerClass).configure().buildValidatorFactory();
>>>
>>>
>>> where provide class can be configured by user or in case no value is
>>> specified by user, Apache BV will be picked as default implementation.
>>>
>>> Thanks
>>> Umesh
>>>
>>>
>>>
>>> On Tue, Oct 15, 2013 at 10:34 PM, Matt Benson <gu...@gmail.com>wrote:
>>>
>>>> ApacheValidatorConfiguration.Properties.VALIDATION_XML_PATH allows you
>>>> to override the location of validation.xml in a manner that is specific to
>>>> Apache BVal, but if you are creating some kind of plugin I'd hardly think
>>>> you'd want to tie yourself to a specific implementation of the Bean
>>>> Validation specification.  What specific pattern of use are you trying to
>>>> support for the hypothetical plugin user?
>>>>
>>>> Matt
>>>>
>>>>
>>>> On Tue, Oct 15, 2013 at 11:48 AM, Umesh Awasthi <umeshawasthi@gmail.com
>>>> > wrote:
>>>>
>>>>> I am trying to test bean validation for my plugin using XML based
>>>>> configuration and while doing i found that i need to place validation/xml
>>>>> file under
>>>>>
>>>>> META-INF/validation.xml inside my resource folder.
>>>>> For me this seems a little strange and who so ever want to use plugin
>>>>> needs to create META-INF folder inside resource folder.
>>>>>
>>>>> I am not sure, if my understanding is correct here and in case i am
>>>>> right, is there any specific reason to choose XML location like this? or
>>>>> can we customize this location
>>>>>
>>>>> --
>>>>> With Regards
>>>>> Umesh Awasthi
>>>>> http://www.travellingrants.com/
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> With Regards
>>> Umesh Awasthi
>>> http://www.travellingrants.com/
>>>
>>>
>>>
>>
>>
>
>
> --
> With Regards
> Umesh Awasthi
> http://www.travellingrants.com/
>
>
>

Re: bean validation using XML

Posted by Matt Benson <gu...@gmail.com>.
I would recommend you allow your user to be a "real" Bean Validation
consumer and force them to bootstrap it in a normal way.  You can't predict
what other technologies they'll be using in conjunction with Struts 2, so
why try?  If you can write your plugin such that it can either be
configured with a ValidatorFactory instance or obtain one using
javax.validation.Validation.buildDefaultValidatorFactory(), then you would
seem to be covered, and you haven't insulated your user from the
responsbility/opportunity of learning how to set up BV metadata in whatever
manner makes sense for his particular scenario, including making his
preferred implementation available.  If, for example, the user is running
in a Java EE 6 or Java EE 6 Web Profile container, he would already have
some Bean Validation implementation available.  Otherwise, he'll have to
choose, but that's better IMO than your plugin providing things that may
not be needed, or worse, potentially causing unanticipated issues by
having, e.g., multiple versions of Apache BVal on the classpath.

Matt


On Tue, Oct 15, 2013 at 12:15 PM, Umesh Awasthi <um...@gmail.com>wrote:

> Hi Matt,
>
> Thanks for your inputs and agree with you, i do not want to bind my
> implementation with specific implementation.
> not sure if i am able to understand second part of your question
> completely.
> I am trying to provide a bridge between Struts2 and Bean validation
> API.While user submit there inputs, i am putting them through Validation
> using BV and if any kind of exception occurring, using Struts2 message API
> to read error messages and display them to UI.
>
> Through this , idea is to let use specify which bean validation they want
> to use be it
> 1. Apache Bean validation
> 2. Hibernate Validator.
>
> I have plan to put Apache Bean Validation as Default validator in case use
> do not specify any preferences and want to use out of box functionality.
>
> Validation.byProvider(this.providerClass).configure().buildValidatorFactory();
>
>
> where provide class can be configured by user or in case no value is
> specified by user, Apache BV will be picked as default implementation.
>
> Thanks
> Umesh
>
>
>
> On Tue, Oct 15, 2013 at 10:34 PM, Matt Benson <gu...@gmail.com>wrote:
>
>> ApacheValidatorConfiguration.Properties.VALIDATION_XML_PATH allows you to
>> override the location of validation.xml in a manner that is specific to
>> Apache BVal, but if you are creating some kind of plugin I'd hardly think
>> you'd want to tie yourself to a specific implementation of the Bean
>> Validation specification.  What specific pattern of use are you trying to
>> support for the hypothetical plugin user?
>>
>> Matt
>>
>>
>> On Tue, Oct 15, 2013 at 11:48 AM, Umesh Awasthi <um...@gmail.com>wrote:
>>
>>> I am trying to test bean validation for my plugin using XML based
>>> configuration and while doing i found that i need to place validation/xml
>>> file under
>>>
>>> META-INF/validation.xml inside my resource folder.
>>> For me this seems a little strange and who so ever want to use plugin
>>> needs to create META-INF folder inside resource folder.
>>>
>>> I am not sure, if my understanding is correct here and in case i am
>>> right, is there any specific reason to choose XML location like this? or
>>> can we customize this location
>>>
>>> --
>>> With Regards
>>> Umesh Awasthi
>>> http://www.travellingrants.com/
>>>
>>>
>>>
>>
>>
>
>
> --
> With Regards
> Umesh Awasthi
> http://www.travellingrants.com/
>
>
>

Re: bean validation using XML

Posted by Umesh Awasthi <um...@gmail.com>.
Hi Matt,

Thanks for your inputs and agree with you, i do not want to bind my
implementation with specific implementation.
not sure if i am able to understand second part of your question completely.
I am trying to provide a bridge between Struts2 and Bean validation
API.While user submit there inputs, i am putting them through Validation
using BV and if any kind of exception occurring, using Struts2 message API
to read error messages and display them to UI.

Through this , idea is to let use specify which bean validation they want
to use be it
1. Apache Bean validation
2. Hibernate Validator.

I have plan to put Apache Bean Validation as Default validator in case use
do not specify any preferences and want to use out of box functionality.

Validation.byProvider(this.providerClass).configure().buildValidatorFactory();


where provide class can be configured by user or in case no value is
specified by user, Apache BV will be picked as default implementation.

Thanks
Umesh



On Tue, Oct 15, 2013 at 10:34 PM, Matt Benson <gu...@gmail.com> wrote:

> ApacheValidatorConfiguration.Properties.VALIDATION_XML_PATH allows you to
> override the location of validation.xml in a manner that is specific to
> Apache BVal, but if you are creating some kind of plugin I'd hardly think
> you'd want to tie yourself to a specific implementation of the Bean
> Validation specification.  What specific pattern of use are you trying to
> support for the hypothetical plugin user?
>
> Matt
>
>
> On Tue, Oct 15, 2013 at 11:48 AM, Umesh Awasthi <um...@gmail.com>wrote:
>
>> I am trying to test bean validation for my plugin using XML based
>> configuration and while doing i found that i need to place validation/xml
>> file under
>>
>> META-INF/validation.xml inside my resource folder.
>> For me this seems a little strange and who so ever want to use plugin
>> needs to create META-INF folder inside resource folder.
>>
>> I am not sure, if my understanding is correct here and in case i am
>> right, is there any specific reason to choose XML location like this? or
>> can we customize this location
>>
>> --
>> With Regards
>> Umesh Awasthi
>> http://www.travellingrants.com/
>>
>>
>>
>
>


-- 
With Regards
Umesh Awasthi
http://www.travellingrants.com/

Re: bean validation using XML

Posted by Matt Benson <gu...@gmail.com>.
ApacheValidatorConfiguration.Properties.VALIDATION_XML_PATH allows you to
override the location of validation.xml in a manner that is specific to
Apache BVal, but if you are creating some kind of plugin I'd hardly think
you'd want to tie yourself to a specific implementation of the Bean
Validation specification.  What specific pattern of use are you trying to
support for the hypothetical plugin user?

Matt


On Tue, Oct 15, 2013 at 11:48 AM, Umesh Awasthi <um...@gmail.com>wrote:

> I am trying to test bean validation for my plugin using XML based
> configuration and while doing i found that i need to place validation/xml
> file under
>
> META-INF/validation.xml inside my resource folder.
> For me this seems a little strange and who so ever want to use plugin
> needs to create META-INF folder inside resource folder.
>
> I am not sure, if my understanding is correct here and in case i am right,
> is there any specific reason to choose XML location like this? or can we
> customize this location
>
> --
> With Regards
> Umesh Awasthi
> http://www.travellingrants.com/
>
>
>