Right, you'd want to try and use 2.3 Constraint composition from the
spec to keep from reimplementing the existing constraints.


-Donald

On 5/9/10 6:54 PM, Carlos Vara wrote:
> I liked your idea when I first read it, but then I realized it is quite
> similar to the payload solution with the disadvantage that you have to
> duplicate the parameters of the annotation that you are "extending".
> 
> On its favour, I would say that IMHO, parameter duplication wouldn't be
> so terrible as hinted by the hibernate guys. At least in my experience,
> validation constraints get aggregated into domain definitions, so if you
> have for example a client code represented in a string, you wouldn't
> annotate it this way:
> 
> @NotNull
> @Size(min=2,max=4)
> @Pattern(regexp="[1-4]*")
> String clientCode;
> 
> As you would have to keep those annotations and their parameters
> synchronized in all the strings that represent a client code. You would do:
> 
> @ClientCode
> String clientCode;
> 
> @NotNull
> @Size(min=2,max=4)
> @Pattern(regexp="[1-4]*")
> ...
> public @interface clientCode {
> // very likely parameter less, as you don't want to keep parameters
> synchronized
> }
> 
> So you would just need to add:
> 
> @ClientCode
> @ListValidation
> public @interface clientCodeIterable {
> // groups, message and payload only, which are mandatory
> }
> 
> 
> Regards,
> Carlos
>  
> 
> 
>     LieGrue,
>     strub
> 
>     --- Carlos Vara <[email protected] <mailto:[email protected]>>
>     schrieb am Fr, 7.5.2010:
> 
>     Von: Carlos Vara <[email protected] <mailto:[email protected]>>
>     Betreff: Re: An interesting post about validating collections
>     An: [email protected]
>     <mailto:[email protected]>
>     Datum: Freitag, 7. Mai, 2010 17:54 Uhr
> 
>     IMHO it isn't business logic, but a pretty valid concern about
>     something that the standard cannot currently solve.
> 
>     To explain myself, take the example given in Hibernate's blog, if
>     emails weren't stored in a String but on their own class, we already
>     have a solution with @Valid.
> 
>     public class User {
>        @NotEmpty
>        private String name;
> 
>        @NotEmpty
>        @Valid
>        private List<Email> emailList;
> 
>     }But if you want to validate a type which you cannot annotate, there
>     is no "clean" way of doing it. Solving it by writing a custom
>     validator like @ListOfEmailStrings (which is what I have been doing
>     atm) is not a good solution as you have to replicate the validation
>     logic of all the annotations that the individual email has.
> 
> 
>     To put this in perspective, if a single email was annotated like this:
> 
> 
>     @NotNull
>     @Email
> 
>     String email;
> 
> 
>     The custom validator for the list of emails will have to replicate
>     the validation logic of those two constraints (as it should never
>     instantiate the validators), and it would also have to be manually
>     mantained to always validate your definition of an email.
> 
> 
>     I personally think that implementing the first solution is a clean
>     way of doing it and fits the role of the library. Of course, that
>     involves waiting, but waiting to be able to do something right is
>     never bad in my book :-)
> 
> 
> 
>     I hope that Hibernate guys don't rush a suboptimal solution like the
>     other ones exposed, as it would be a clear point of incompatibility
>     with Apache's version.
> 
>     Regards,
>     Carlos
> 
> 
>     On Fri, May 7, 2010 at 3:19 PM, Gerhard Petracek
>     <[email protected] <mailto:[email protected]>> wrote:
> 
> 
>     we are currently discussing it in the eg.maybe we should just wait
>     for [1].
>     regards,gerhard
>     [1] http://openjdk.java.net/projects/type-annotations/
> 
> 
> 
> 
> 
>     http://www.irian.at
> 
>     Your JSF powerhouse -
>     JSF Consulting, Development and
>     Courses in English and German
> 
>     Professional Support for Apache MyFaces
> 
> 
> 
> 
>     2010/5/7 Mark Struberg <[email protected] <mailto:[email protected]>>
> 
> 
> 
> 
>     I honestly think this goes into the wrong direction.
> 
>     This is business logic, and if we start to provide annotations for
>     all those kinds of problems, it will end up getting terribly
>     complicated.
> 
> 
> 
>     I'd prefer to keep it simple and stupid.
> 
> 
> 
>     LieGrue,
> 
>     strub
> 
> 
> 
> 
> 
>     >
> 
>     >Von: Carlos Vara <[email protected] <mailto:[email protected]>>
> 
>     >An: [email protected]
>     <mailto:[email protected]>
> 
>     >Gesendet: Freitag, den 7. Mai 2010, 10:57:11 Uhr
> 
>     >Betreff: An interesting post about validating collections
> 
>     >
> 
>     >http://in.relation.to/Bloggers/AValidationStickler
> 
>     >
> 
>     >Currently as an user, I was solving this by writing custom
>     validators, which it seems is no more of a hack than the other
>     proposed solutions (except the one that implies waiting for JDK7 to
>     hopefully implement JSR-308).
> 
> 
> 
> 
> 
>     >
> 
>     >Any of you guys have an idea of how we could implement it?
> 
>     >
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 

Reply via email to