[
https://hibernate.onjira.com/browse/BVAL-208?page=com.atlassian.jira.plug...
]
Hardy Ferentschik edited comment on BVAL-208 at 4/3/12 8:55 AM:
----------------------------------------------------------------
{quote}
* define the group to validate in a method level annotation (parameter etc)
{quote}
I am not quite sure this is needed. If you have an actual constraint (_NotNull_, _Size_,
etc) you can specify the groups. If you want to validate a whole object you add _@Valid_
to the parameter and the actual constraints (with their specified) groups are getting
validated. I guess what I am saying here is that a group belongs to an actual constraint
not to a marker (_@Valid_) which basically says all constraints of the anntated element
must be valid.
{code}
public interface GroupA {
}
{code}
{code}
public interface GroupB {
}
{code}
{code}
public class Command {
@NotNull(groups = GroupA.class)
String name;
}
{code}
{code}
public class Executor {
public void doSomething((a)Valid(groups=GroupB.class) Command command) {
// ...
}
}
{code}
{code}
// something like this to handle method validation
public class ValidationInvocationHandler {
//...
public Object invoke(Object object, Method method, Object[] args) throws Throwable {
Set<MethodConstraintViolation<Object>> constraintViolations;
// ...
constraintViolations = validator.validateAllParameters( object, method, args,
GroupB.class );
if ( !constraintViolations.isEmpty() ) {
throw new MethodConstraintViolationException( constraintViolations );
}
Object result = method.invoke( wrapped, args );
constraintViolations = validator.validateReturnValue( wrapped, method, result, groups );
if ( !constraintViolations.isEmpty() ) {
throw new MethodConstraintViolationException( constraintViolations );
}
return result;
}
{code}
Is a newly created _Command_ instance with a _null_ name valid in this case?
was (Author: hardy.ferentschik):
{quote}
* define the group to validate in a method level annotation (parameter etc)
{quote}
I am not quite sure this is needed. If you have an actual constraint (_NotNull_, _Size_,
etc) you can specify the groups. If you want to validate a whole object you add _@Valid_
to the parameter and the actual constraints (with their specified) groups are getting
validated. I guess what I am saying here is that a group belongs to an actual constraint
not to a marker (_@Valid_) which basically says all constraints of the anntated element
must be valid.
{code}
public interface GroupA {
}
{code}
public interface GroupB {
}
{code}
{code}
public class Command {
@NotNull(groups = GroupA.class)
String name;
}
{code}
{code}
public class Executor {
public void doSomething((a)Valid(groups=GroupB.class) Command command) {
// ...
}
}
{code}
{code}
// something like this to handle method validation
public class ValidationInvocationHandler {
//...
public Object invoke(Object object, Method method, Object[] args) throws Throwable {
Set<MethodConstraintViolation<Object>> constraintViolations;
// ...
constraintViolations = validator.validateAllParameters( object, method, args,
GroupB.class );
if ( !constraintViolations.isEmpty() ) {
throw new MethodConstraintViolationException( constraintViolations );
}
Object result = method.invoke( wrapped, args );
constraintViolations = validator.validateReturnValue( wrapped, method, result, groups );
if ( !constraintViolations.isEmpty() ) {
throw new MethodConstraintViolationException( constraintViolations );
}
return result;
}
{code}
Is a newly created _Command_ instance with a _null_ name valid in this case?
support groups translation when cascading operations (hosted on
@Valid or not)
------------------------------------------------------------------------------
Key: BVAL-208
URL:
https://hibernate.onjira.com/browse/BVAL-208
Project: Bean Validation
Issue Type: Improvement
Affects Versions: 1.0 final
Reporter: Marc Schipperheyn
The @Valid annotation should implement the group attribute in order to make validation
completely annotation driven. Currently, we need to manually call the validate method on
the validator if we want to validate based on groups.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira