org.qi4j.library.struts2
Class ConstraintViolationInterceptor
java.lang.Object
com.opensymphony.xwork2.interceptor.AbstractInterceptor
org.qi4j.library.struts2.ConstraintViolationInterceptor
- All Implemented Interfaces:
- com.opensymphony.xwork2.interceptor.Interceptor, Serializable
public class ConstraintViolationInterceptor
- extends com.opensymphony.xwork2.interceptor.AbstractInterceptor
ConstraintViolationInterceptor adds constraint violations from the ActionContext to the Action's field errors.
This interceptor adds any error found in the ActionContext
's constraint violations map as a field error
(provided that the action implements ValidationAware
). In addition, any field that contains a constraint
violation has its original value saved such that any subsequent requests for that value return the original value
rather than the value in the action. This is important because if the value "abc" is submitted and can't be set
on a property requiring at least 5 characters, we want to display the original string ("abc") again rather than the
original value (likely an empty string, which would make very little sense to the user).
This is similar, in principle, to the XWork ConversionErrorInterceptor and much of the code is reflects that.
- See Also:
- Serialized Form
Methods inherited from class com.opensymphony.xwork2.interceptor.AbstractInterceptor |
destroy, init |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CONTEXT_CONSTRAINT_VIOLATIONS
public static final String CONTEXT_CONSTRAINT_VIOLATIONS
ConstraintViolationInterceptor
public ConstraintViolationInterceptor()
getOverrideExpr
protected Object getOverrideExpr(com.opensymphony.xwork2.ActionInvocation invocation,
ConstraintViolationInterceptor.FieldConstraintViolations violations)
intercept
public String intercept(com.opensymphony.xwork2.ActionInvocation invocation)
throws Exception
- Specified by:
intercept
in interface com.opensymphony.xwork2.interceptor.Interceptor
- Specified by:
intercept
in class com.opensymphony.xwork2.interceptor.AbstractInterceptor
- Throws:
Exception
message
protected String message(Object target,
String propertyName,
ConstraintViolation constraintViolation,
com.opensymphony.xwork2.util.ValueStack stack)
messageKey
protected String messageKey(Object target,
String propertyName,
ConstraintViolation violation)
The message key is generated based on the type of the target, the name of the property and the type of the
constraint violation. So, if the target has type ItemEntity with a name property that has a not empty constraint
and the user doesn't enter anything for the value, the corresponding message key would be
'item.name.not.empty.constraint.violated'.
Note that if the type name of the target ends with 'Composite' or 'Entity', those will be removed and the
rest of the name will be converted from camel-case to a dot notation. This is true of the constraint types as
well. So a constraint named NotEmpty will be converted to not.empty as in the example above.
- Parameters:
target
- JAVADOCpropertyName
- JAVADOCviolation
- JAVADOC
- Returns:
- JAVADOC