On 4 janv. 2012, at 22:54, Cemo wrote:

Hi,

Emmanuel, I can really see your points about ordering numbers (the salience approach). I think that you are totally right. But in terms of usability declaring again and again interfaces are killing usability. At your example there is a still need for declaring them. And also at the order of the     constraints are can not be reached by reflection. 

You mean by Java reflection? Yes it can. From the DomainObject class you can reach the GroupSequence annotation. That's how a Bean Validation provider does it anyways.
Why do you need to access the order by the way?


At this point I believe that defining order explicitly is the best. Maybe like GroupSequence we can use ConstraintSequence whose target type "Field, Method, Type" as opposite to GroupSequence whose target type "Type". GroupSequence implies group related operations as expected, whereas ConstraintSequence implies ConstraintSequence. For me really it makes sense.

What would @ConstraintSequence look like? From what you are saying, it would have the notion of group in there so I imaging that would need to be either global or applied on every target.

```
public class DomainObject {

       @ConstraintSequence(value={PER_TARGET))
       @Size(max=50, ordering=1) // constraint 1a
       @Pattern(regexp="[a-z]*", ordering=2)  // constraint 1b
       private String name;

       @ConstraintSequence(value={PER_TARGET))
       @Size(max=20,  ordering=1) // constraint 2a
       @URL(ordering=2) // constraint 2b
       private String email;

       @ConstraintSequence(value={PER_TARGET))
       @Size(max=100, ordering=1) // constraint 3a
       @Pattern(regexp="[0-9]*", ordering=2) // constraint 3b
       private String password;
}
```

Is that what you had in mind?


For my use case I just want to not declaring again and again interfaces. For M class and N field I have to declare (M) x (N) x (Annotation Count) Interface. And without declaring interface I would like to have short circuit feature. 

With my proposal you need to define A interfaces instead of AxMxN - A being the number of separate phases in validation - and reuse the same set of interfaces for all your classes and all your fields in a given project.


Thanks    





But there is another point too. Groups are used also for partial validation. And groups are really implies this partial validation with its name very good.

On 4 January 2012 16:29, <beanvalidation-dev-request@lists.jboss.org> wrote:
Message: 3
Date: Wed, 4 Jan 2012 15:25:10 +0100
From: Emmanuel Bernard <emmanuel@hibernate.org>
Subject: Re: [bv-dev] Ordered Validation (practically)
To: beanvalidation-dev  List <beanvalidation-dev@lists.jboss.org>
Message-ID: <9B5F338F-1682-438B-8270-A2A0E9DADE81@hibernate.org>
Content-Type: text/plain; charset=us-ascii

I have what I think is a nice solution for BVAL-248 and for the uses case Cemo has

The issue in this case is that you want the logic of group sequence but only per target (property, class, annotation).

We can dot he following for that reusing HV-462's example

```
interface Cheap {}
interface Expensive {}

@GroupSequence(value={Cheap.class,Expensive.class}, ordering=PER_TARGET)
public class DomainObject {

       @Size(max=50, groups=Cheap.class) // constraint 1a
       @Pattern(regexp="[a-z]*", groups=Expensive.class)  // constraint 1b
       private String name;

       @Size(max=20, groups=Cheap.class) // constraint 2a
       @URL(groups=Expensive.class) // constraint 2b
       private String email;

       @Size(max=100, groups=Cheap.class) // constraint 3a
       @Pattern(regexp="[0-9]*", groups=Expensive.class) // constraint 3b
       private String password;
}
```

The default @GroupSequence.ordering would be GLOBAL which is the current behavior.

This solution is not technically as orthogonal than a true salience model but would that work for the use cases you have in mind?

We can apply the same kind of solution on @ReportAsSingleViolation

What do you think?

Emmanuel

_______________________________________________
beanvalidation-dev mailing list
beanvalidation-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/beanvalidation-dev