public class ConversionErrorInterceptor extends AbstractInterceptor
This interceptor adds any error found in the ActionContext
's conversionErrors map as a field error (provided
that the action implements ValidationAware
). In addition, any field that contains a validation error 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 converted to an int, we want to
display the original string ("abc") again rather than the int value (likely 0, which would make very little sense to
the user).
Interceptor parameters:
Extending the interceptor:
Because this interceptor is not web-specific, it abstracts the logic for whether an error should be added. This allows for web-specific interceptors to use more complex logic in theshouldAddError(java.lang.String, java.lang.Object)
method for when a value
has a conversion error but is null or empty or otherwise indicates that the value was never actually entered by the
user.
Example code:
<action name="someAction" class="com.examples.SomeAction"> <interceptor-ref name="params"/> <interceptor-ref name="conversionError"/> <result name="success">good_result.ftl</result> </action>
Modifier and Type | Field and Description |
---|---|
static String |
ORIGINAL_PROPERTY_OVERRIDE |
Constructor and Description |
---|
ConversionErrorInterceptor() |
Modifier and Type | Method and Description |
---|---|
protected String |
escape(Object value) |
protected Object |
getOverrideExpr(ActionInvocation invocation,
Object value) |
String |
intercept(ActionInvocation invocation)
Override to handle interception
|
protected boolean |
shouldAddError(String propertyName,
Object value) |
destroy, init
public static final String ORIGINAL_PROPERTY_OVERRIDE
protected Object getOverrideExpr(ActionInvocation invocation, Object value)
public String intercept(ActionInvocation invocation) throws Exception
AbstractInterceptor
intercept
in interface Interceptor
intercept
in class AbstractInterceptor
invocation
- the action invocationActionInvocation.invoke()
, or from the interceptor itself.Exception
- any system-level error, as defined in Action.execute()
.Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.