[
http://opensource.atlassian.com/projects/hibernate/browse/HV-198?page=com...
]
Emmanuel Bernard updated HV-198:
--------------------------------
Summary: Wrong constraint violation path when adding subnode error to subnode (was:
Wront constraint violation path when adding subnode error to subnode)
Wrong constraint violation path when adding subnode error to subnode
--------------------------------------------------------------------
Key: HV-198
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HV-198
Project: Hibernate Validator
Issue Type: Bug
Components: engine
Affects Versions: 4.0.0.Beta2
Environment: Hibernate Validator Beta 2, JRE 1.6
Reporter: Alexey Romanchuk
Assignee: Hardy Ferentschik
Priority: Critical
Fix For: 4.0.0.Beta3
Original Estimate: 1 hour
Time Spent: 52 minutes
Remaining Estimate: 0 minutes
When I use subnode error in validator and object is part of another with @Valid tag I
have incorrect path in ConstrainViolation.
Example:
I got "start" instead of "interval.start". Looks like we need merge
paths when ConstraintViolationImpl is created
class Item
{
@Valid
Interval interval;
}
@StartLessThatEnd
class Interval
{
int start;
int end;
}
public class ValidatorTest
{
public static void main( String[] args )
{
Item item = new Item();
item.interval = new Interval();
item.interval.start = 10;
item.interval.end = 5;
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
ConstraintViolation<Item> c = factory.getValidator().validate( item
).iterator().next();
System.out.println( c.getPropertyPath() );
}
}
@Target( ElementType.TYPE )
@Retention( RetentionPolicy.RUNTIME )
@Constraint( validatedBy = StartLessThatEndImpl.class )
public @interface StartLessThatEnd
{
String message() default "x";
Class<?>[] groups() default {};
Class<? extends ConstraintPayload>[] payload() default { };
}
public class StartLessThatEndImpl implements ConstraintValidator<StartLessThatEnd,
Interval>
{
@Override
public void initialize( StartLessThatEnd constraintAnnotation )
{
}
@Override
public boolean isValid( Interval value, ConstraintValidatorContext c )
{
if ( value.start > value.end )
{
c.disableDefaultError();
c.buildErrorWithMessageTemplate( c.getDefaultErrorMessageTemplate() ).addSubNode(
"start" ).addError();
return false;
}
return true;
}
}
--
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