myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rudy De Busscher <rdebussc...@gmail.com>
Subject [Codi] Idea for new functionality: method parameter validation
Date Mon, 22 Nov 2010 20:10:23 GMT
Hi all,

BeanValidation is promoted as *THE validation framework* in the EE
environment.  it can already be used in JPA and JSF.  In the future they
plan to have it also in other areas like JAX-RS.

Another area where we could start using it, is with CDI.  With the creation
of an Interceptor, it is possible to develop a mechanism that allow
validation of method parameter values.

Aparently Apache BVal is taking this up (thx Gerhard for the input, see here
http://carinae.net/2010/04/automatic-validation-method-calls-with-jsr-303-appendix-c/),
but a generic solution could be made available in Codi.  Since there
is
no method forseen in the BeanValidation spec to validate a value based on an
annotation (only methods for validating a property within a class or a
complete object), I was forced to create a hack with dynamically created
classes.

But in a POC I was able to use the following declarations

*   @ParameterValidation
   public String sayHelloMinimumLength(@Size(min = 3) String name) {
       return "Hello "+name;
   }

   @ParameterValidation
   public String sayHello(@NotNull @Valid Person person) {
       return "Hello "+person.getLastName();
   }*

And I did some small (but successful) tests in the following environments
- Plain SE (JUnit tests)
- Tomcat 6
- JBoss 6 (M5)

The performance is also acceptable.  Executing 1000 tests on the
sayHelloMinimumLength method as described above, adds about 300 ms (in
total, so 0.3 ms per call).

So with this message I would like to have the opinion of the community about
adding such functionality to Codi.  I think we have 3 options:

1) Add it to Codi itself (I think the BV module is the best candidate)
2) Put the logic in an add-on because it is useful but not all projects
can/will use it.
3) Spend our time to other topics because it is useless. [?]

If you like the idea, I do some further work on the code an supply a patch
or the add-on.

Regards
Rudy.

Mime
View raw message