com.opensymphony.xwork.interceptor
Class ConversionErrorInterceptor

java.lang.Object
  extended by com.opensymphony.xwork.interceptor.AroundInterceptor
      extended by com.opensymphony.xwork.interceptor.ConversionErrorInterceptor
All Implemented Interfaces:
Interceptor, Serializable
Direct Known Subclasses:
WebWorkConversionErrorInterceptor

public class ConversionErrorInterceptor
extends AroundInterceptor

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 the shouldAddError(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>
 
 
ConversionErrorInterceptor adds conversion errors from the ActionContext to the Action's field errors.

Author:
Jason Carreira
See Also:
Serialized Form

Field Summary
static String ORIGINAL_PROPERTY_OVERRIDE
           
 
Fields inherited from class com.opensymphony.xwork.interceptor.AroundInterceptor
log
 
Constructor Summary
ConversionErrorInterceptor()
           
 
Method Summary
protected  void after(ActionInvocation dispatcher, String result)
          Called after the invocation has been executed.
protected  void before(ActionInvocation invocation)
          Called before the invocation has been executed.
protected  Object getOverrideExpr(ActionInvocation invocation, Object value)
           
protected  boolean shouldAddError(String propertyName, Object value)
           
 
Methods inherited from class com.opensymphony.xwork.interceptor.AroundInterceptor
destroy, init, intercept
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORIGINAL_PROPERTY_OVERRIDE

public static final String ORIGINAL_PROPERTY_OVERRIDE
See Also:
Constant Field Values
Constructor Detail

ConversionErrorInterceptor

public ConversionErrorInterceptor()
Method Detail

getOverrideExpr

protected Object getOverrideExpr(ActionInvocation invocation,
                                 Object value)

after

protected void after(ActionInvocation dispatcher,
                     String result)
              throws Exception
Description copied from class: AroundInterceptor
Called after the invocation has been executed.

Specified by:
after in class AroundInterceptor
result - the result value returned by the invocation
Throws:
Exception

before

protected void before(ActionInvocation invocation)
               throws Exception
Description copied from class: AroundInterceptor
Called before the invocation has been executed.

Specified by:
before in class AroundInterceptor
Throws:
Exception

shouldAddError

protected boolean shouldAddError(String propertyName,
                                 Object value)

WebWork Project Page