| 1 |
|
package org.trails.validation; |
| 2 |
|
|
| 3 |
|
import org.apache.tapestry.valid.FieldTracking; |
| 4 |
|
import org.apache.tapestry.valid.RenderString; |
| 5 |
|
import org.hibernate.validator.InvalidStateException; |
| 6 |
|
import org.hibernate.validator.InvalidValue; |
| 7 |
|
import org.trails.descriptor.IClassDescriptor; |
| 8 |
|
import org.trails.descriptor.IPropertyDescriptor; |
| 9 |
|
|
| 10 |
23 |
public class HibernateValidationDelegate extends TrailsValidationDelegate |
| 11 |
|
{ |
| 12 |
|
|
| 13 |
|
public void record(IClassDescriptor descriptor, InvalidStateException invalidStateException) |
| 14 |
|
{ |
| 15 |
6 |
for (InvalidValue invalidValue : invalidStateException.getInvalidValues()) |
| 16 |
|
{ |
| 17 |
|
|
| 18 |
3 |
IPropertyDescriptor propertyDescriptor = descriptor.getPropertyDescriptor(invalidValue.getPropertyName()); |
| 19 |
3 |
FieldTracking fieldTracking = null; |
| 20 |
3 |
String message = null; |
| 21 |
3 |
if (propertyDescriptor != null) |
| 22 |
|
{ |
| 23 |
3 |
fieldTracking = (FieldTracking) getFieldTracking(propertyDescriptor.getDisplayName()); |
| 24 |
3 |
message = propertyDescriptor.getDisplayName() + " " + invalidValue.getMessage(); |
| 25 |
|
} else |
| 26 |
|
{ |
| 27 |
|
|
| 28 |
0 |
setFormComponent(null); |
| 29 |
|
|
| 30 |
0 |
fieldTracking = findCurrentTracking(); |
| 31 |
0 |
message = invalidValue.getMessage(); |
| 32 |
|
} |
| 33 |
|
|
| 34 |
3 |
fieldTracking.setErrorRenderer(new RenderString(message)); |
| 35 |
|
} |
| 36 |
3 |
} |
| 37 |
|
|
| 38 |
|
} |