roman.stumm wrote:
Let me summarize the questions and problems we had while implementing JSR303 based on the early-darft spec. I try so list the points as short as I can with references to the chapters in the spec:
* chapter 2.1:
In some code examples, @ValidatorClass is used instead of @ConstraintValidator => typo?
Yep, typo due to a last minute change.
Quote:
* Some APIs seem quite annotation-centric
Code:
chapter 5.2: ElementDescriptor.getElementType(),
chapter 5.3: ConstraintDescriptor.getAnnotation()
chapter 2.3: Constraint.initialize(Annotation)
==> what to do when constraintdescription originates from a xml file / is not based on annotations?
Generate the annotation. Annotations are the meta model today.
Quote:
* chapter 5.2: Is ElementDescriptor.getElementType() ambiguous? Isn't this rather an access-strategy per constraint than per property?
Code:
class A { @NotEmpty protected String name; }
class B extends A { @Length(max = 30) public String getName() { return name; } }
validator.getConstraintsForProperty(“name”).getElementType() => FIELD or METHOD? (@NotEmpty: FIELD, @Length: METHOD)
I agree, I noticed that. AFAIR it has some implications, but we need to address that.
Quote:
* chapter 3.1.2: Do you plan to explain whether or not annotation of setter-methods is supported (access strategy would be unclear)?
setter annotation are not supported, does it read differently?
Quote:
* chapter 3.1.2: How is the access-strategy for annotated overwritten methods:
Code:
class A {
@NotEmpty protected String getName() { return “dummy”; }
}
class B extends A {
@NotEmpty public String getName() { return “”; }
}
==> is method A#getName() called? I don't think so.
A#getName() is not called as it would require some bytecode manipulation, but constraints on A#getName() will be called. In your example @NotEmpty will be checked twice
This is explained in 3.3.
Quote:
* 3.5 validation routine: Is it really neccessary to specify that field level validations are executed BEFORE property level validations or should this be an implementation detail instead?
Because: Sequence can be defined with groups/groupsequences. In case of InvalidConstraints found, validation will not stop until the group is completly validated anyway.
Why do you think the wording in 3.5 implies an order between field and method? I does not.
Quote:
* chapter 3.4: I had problems understanding the required behaviour for groupSequence handling:
InvalidConstraint.groups: String instead of String[] to contain the group, where the invalidconstraint has occurred?
This is not very well defined. The thing is I am not sure we can define that property (especially because of the group sequence expendability). We are looking for feedback on the usefulness of this feature.
Quote:
* chapter 4.1.1: Validator.validateProperty() + Validator.validateValue(propertyName,value,groups...)
can propertyName contain a propertyPath (with dot-notation)?
Do you think it is useful?
Quote:
* chapter 3.1.3: How will the @Valid annotation determine the target type , especially in case of to-many relationships? (Invoke getClass() on each instance in the collection? Using reflection on the generic collection type can be a problem when generic type is Object or some interface type.) I would suggest to add an optional attribute like “hint”/”id” or “targetClass” to the @Valid annotation. That would open up the possibility to have a different validation per association role:
Code:
class User {
@Valid(hint=”HomeContact”) private Contact home;
@Valid(hint=”OfficeContact”) private Contact office;
}
No this is a runtime resolution. We probably need to be be more clear about that.
Thanks for your feedback