incubator-bval-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carlos Vara <bashfl...@gmail.com>
Subject Re: An interesting post about validating collections
Date Fri, 07 May 2010 15:54:49 GMT
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 <gerhard.petracek@gmail.com
> 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 <struberg@yahoo.de>
>
> 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 <bashflyng@gmail.com>
>> >An: bval-user@incubator.apache.org
>> >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?
>> >
>>
>>
>>
>

Mime
View raw message