Hi again,

>> However, I have the strong feeling that we (I and T5IoC) can do much more 
>> with just a little more effort... but unfortunately I have no time to dive 
>> into the code to find this out
> Don't forget that Tapestry-IoC is about IoC and I think that's the only thing 
> it should focus.

Yes, I meant something like: By fully exploit the power of T5-ioc I can do a 
lot more with just little effort to do it


>> ================================================================================
>> 
>> The Problem
>> ========
>> 
>> The non web application under design receives command-line arguments as 
>> inputs.
>> Some of them are optional, some of them have constrained values (i.e., 
>> ranges), and some of them must have specific values.
> 
> I agree with Martin Kersten: this is an interface problem, not an IoC one.
> Command-line is just another interface between your code and everything 
> outside it, be it users, other code or other machines.
> That shouldn't be part of Tapestry-IoC.

I have been misunderstood, sorry for not explaining myself properly... Let me 
try again:

I do not want to extend T5-IoC with a validation, I just want to use its power 
(as well as the available T5 modules) to create a new module that I can use to 
validate the inputs my application receive via command-line.

To do so I would like to leverage the validation framework(s) that are already 
in place. 

Now the question (or dilemma) is: how to best approach this problems ?

Using the T5-Web validation is apparently not applicable or not really clean 
because in my case I don't need to for example  "render" validators, 
bubble/intercept events, and so on.
As something simple like inject a "validator" and invoking validate() should be 
ok in my case.

Here we come to Thiago's suggestions:
> For the validation, why don't you use Bean Validation aka JSR 303?

I never used it before, so I gave it a try... with no luck so far :(

These are a list of things I did:

- To "enable" the validation I created an ApplicationConfigurationBean and 
annotate its fields with the required annotations. (My hope is to have a 
factory that create this bean from the CLI specs/contributions)

- Then I tried to use plain "Bean Validation aka JSR 303", and failed because 
there are incompatible library versions for logging ( -.-' ) (I cannot change 
the exclusion/inclusion in maven because some lib require some version while 
the validators one require some others)

- So I resort to use the tapestry-beanvalidation module:
        - I added the dependency in my pom 
(<dependency><groupId>org.apache.tapestry</groupId><artifactId>tapestry-beanvalidator</artifactId><version>5.3.7</version></dependency>)
        - Declare: BeanValidatorModule.class as Submodule of my application 
module
        - Try to build the registry for eventually getting an instance of 
Validator like this: javax.validation.Validator validator = 
registry.getService(Validator.class);

During the registry build I got (intermittently) one of the following 
exceptions (I am using JUnit to rung the test):

java.lang.IllegalArgumentException: Contribution 
org.apache.tapestry5.beanvalidator.BeanValidatorModule.addWorker(OrderedConfiguration)
 (at BeanValidatorModule.java:111) is for service 'interface 
org.apache.tapestry5.services.transform.ComponentClassTransformWorker2' 
qualified with marker annotations [interface 
org.apache.tapestry5.ioc.annotations.Primary], which does not exist.
        at 
org.apache.tapestry5.ioc.internal.RegistryImpl.validateContributeDefs(RegistryImpl.java:246)
        at 
org.apache.tapestry5.ioc.internal.RegistryImpl.<init>(RegistryImpl.java:205)
        at 
org.apache.tapestry5.ioc.RegistryBuilder.build(RegistryBuilder.java:177)
        at 
at.ac.tuwien.iter.validation.JSR303Test.setupValidation(JSR303Test.java:64) << 
My Test Class 

--

java.lang.IllegalArgumentException: Contribution 
org.apache.tapestry5.beanvalidator.BeanValidatorModule.addBeanValidationStack(MappedConfiguration)
 (at BeanValidatorModule.java:104) is for service 'interface 
org.apache.tapestry5.services.javascript.JavaScriptStackSource' qualified with 
marker annotations [], which does not exist.
        at 
org.apache.tapestry5.ioc.internal.RegistryImpl.validateContributeDefs(RegistryImpl.java:246)
        at 
org.apache.tapestry5.ioc.internal.RegistryImpl.<init>(RegistryImpl.java:205)
        at 
org.apache.tapestry5.ioc.RegistryBuilder.build(RegistryBuilder.java:177)
        at 
at.ac.tuwien.iter.validation.JSR303Test.setupValidation(JSR303Test.java:64) << 
My Test Class 

===============

Is there something obviously wrong that I am doing here ? Maybe some missing 
library/dep , a configuration file, or something else ?




BTW, I am using T5 version 5.3.7 
(<dependency><groupId>org.apache.tapestry</groupId><artifactId>tapestry-ioc</artifactId><version>5.3.7</version></dependency>)

Just for the record, I also tried what's described by Taha in his blog 
(http://tawus.wordpress.com/2011/05/12/tapestry-magic-12-tapestry-ioc-aware-jsr-303-custom-validators/)
 again with no luck.

A small remark/suggestion ... when you publish code - which is a great thing - 
please remember to put also references for any configuration or dependency that 
must be met to properly run it.
In my case for example, it is not clear what I need to put in my pom 
(validation dep ? hibernat implementation of the validation API ? both ? 
tapestry-hibernate (which version) ? tapestry-beanvalidator ? etc.

Many thanks for the great work !

Reply via email to