[Hibernate-JIRA] Created: (BVAL-211) Consider making javax.validation.ValidatorContext a self-referential generic type
by Gunnar Morling (JIRA)
Consider making javax.validation.ValidatorContext a self-referential generic type
---------------------------------------------------------------------------------
Key: BVAL-211
URL: http://opensource.atlassian.com/projects/hibernate/browse/BVAL-211
Project: Bean Validation
Issue Type: Improvement
Components: spec-general
Affects Versions: 1.0 final
Reporter: Gunnar Morling
Priority: Minor
It should be investigated whether the interface javax.validation.ValidatorContext could be re-defined as self-referential generic type as follows:
{code:java}
public interface ValidatorContext <V extends ValidatorContext<V>> {
V messageInterpolator(MessageInterpolator messageInterpolator);
V traversableResolver(TraversableResolver traversableResolver);
V constraintValidatorFactory(ConstraintValidatorFactory factory);
Validator getValidator();
}
{code}
Provider-specific extensions of this interface (such as [HibernateValidatorContext|https://github.com/hibernate/hibernate-validato...]) then wouldn't have to re-define all of ValidatorContext's methods returning their own type (which they currently must do in order to allow for the method chaining pattern to work correctly).
Generally this is a breaking change, as existing implementations wouldn't compile with the proposed new version of the interface. But as it is intended to be implemented by BV providers only, this seems acceptable. API users would get a raw type warning if they have variables of type ValidatorContext. This should happen very rarely though, as ValidatorContext typically is only used in chained method calls (with a final getValidator() invocation) but not assigned to a variable.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years, 10 months
[Hibernate-JIRA] Created: (HV-462) Allow ordered validator's annotations
by Pavla Nováková (JIRA)
Allow ordered validator's annotations
-------------------------------------
Key: HV-462
URL: http://opensource.atlassian.com/projects/hibernate/browse/HV-462
Project: Hibernate Validator
Issue Type: New Feature
Affects Versions: 4.1.0.Final
Reporter: Pavla Nováková
1) Consider domain object with simple constraints (just to demonstrate required feature, my real example uses custom cost-expensive validation of pictures):
{code}
public class DomainObject {
@Size(max=50) // constraint 1a
@Pattern(regexp="[a-z]*") // constraint 1b
private String name;
@Size(max=20) // constraint 2a
@URL // constraint 2b
private String email;
@Size(max=100) // constraint 3a
@Pattern(regexp="[0-9]*") // constraint 3b
private String password;
{code}
2) Consider validation requirements:
* all properties should be validated together (like one virtual group)
* FOR EACH PROPERTY validation should occur in ordered steps given by order of annotations for given property (if first validation step fails, SKIP following validation process on given property and add validation message specific to failed / last validated constraint for the property)
3) Why it is useful:
* simple cost-effective validation followed by cost-expensive validation (not executed if simple constraint fails)
* we get just the "main and specific validation error" (otherwise we have to iterate over all errors "to find the cause" or we display two or more errors for one property which is not user-friendly according my opinion)
3) What is unusable:
* groups and group sequences (it is not possible to create proper combination of groups and sequences for more than one property with two or more constraints)
* composed constraints (@ReportAsSingleViolation included)
** we cannot use @ReportAsSingleViolation since we want specific message for each failed constraint
** and main problem is: if we use composed constraints all constraints are evaluated for given property
4) Proposed solution:
* add optional order attribute to validator annotations and stop validation on first failure if order is specified
* possibly this can be configured on global validator level with property "skipOnFirstFailure" together with some given convention for annotation order
Please let me know if need better explanation or working examples.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years, 10 months
[Hibernate-JIRA] Created: (BVAL-255) Simplify GroupSequence for ordered checking
by Cemo Koc (JIRA)
Simplify GroupSequence for ordered checking
-------------------------------------------
Key: BVAL-255
URL: http://opensource.atlassian.com/projects/hibernate/browse/BVAL-255
Project: Bean Validation
Issue Type: New Feature
Components: spec-general
Affects Versions: 1.0 final
Reporter: Cemo Koc
The JSR 303 is becoming defacto solution at enterprise level projects however I think that it has a significant useless part. The current implementation states group sequence must be utilized to ordered validation. In order to use group sequence, one has to define interfaces for each order sequence such this:
{code}
public class AccountBean {
@CheapValidation(groups=Name1.class)
@ExpensiveValidation(groups=Name2.class)
@VeryExpensiveValidation(groups=Name3.class)
String name;
@CheapValidation(groups=Surname1.class)
@ExpensiveValidation(groups=Surname2.class)
@VeryExpensiveValidation(groups=Surname3.class)
String surname;
public interface Name1 {}
public interface Name2 {}
public interface Name3 {}
@GroupSequence({Name1.class, Name2.class, Name3.class})
public interface Name {}
public interface Surname1 {}
public interface Surname2 {}
public interface Surname3 {}
@GroupSequence({Surname1.class, Surname2.class, Surname3.class})
public interface Surname {}
}
{code}
Look the code how it is ugly and useless. What I am offering is a simplified version of ordering such this:
{code}
public class AccountBean {
@CheapValidation(order=0,groups=Name1.class)
@ExpensiveValidation(order=1,groups=Name2.class)
@VeryExpensiveValidation(order=2,groups=Name3.class)
String name;
@CheapValidation(order=0,groups=Surname1.class)
@ExpensiveValidation(order=1,groups=Surname2.class)
@VeryExpensiveValidation(order=2,groups=Surname3.class)
String surname;
}
{code}
Almost all enterprise projects needs such kind of things. For example lets say that you want to validate email field by NotEmpty and UniqueAtDatabase. Why should we show two error messages in this case? Shortly, to increase usability and adaptability please solve this issue.
PS: This issue is cross posted here and forums.
https://forum.hibernate.org/viewtopic.php?f=26&t=1007328
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
11 years, 10 months