FileDocCategorySizeDatePackage
StrutsConversionErrorInterceptor.javaAPI DocExample3946Mon Jul 23 13:26:52 BST 2007org.apache.struts2.interceptor

StrutsConversionErrorInterceptor

public class StrutsConversionErrorInterceptor extends com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor
This interceptor extends {@link ConversionErrorInterceptor} but only adds conversion errors from the ActionContext to the field errors of the action if the field value is not null, "", or {""} (a size 1 String array with only an empty String). See {@link ConversionErrorInterceptor} for more information, as well as the Type Conversion documentation.

Interceptor parameters:

  • None

Extending the interceptor:

There are no known extension points for this interceptor.


<action name="someAction" class="com.examples.SomeAction">
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
<result name="success">good_result.ftl</result>
</action>

see
com.opensymphony.xwork2.ActionContext#getConversionErrors()
see
ConversionErrorInterceptor

Fields Summary
private static final long
serialVersionUID
Constructors Summary
Methods Summary
protected java.lang.ObjectgetOverrideExpr(com.opensymphony.xwork2.ActionInvocation invocation, java.lang.Object value)


          
        ValueStack stack = invocation.getStack();

        try {
            stack.push(value);

            return "'" + stack.findValue("top", String.class) + "'";
        } finally {
            stack.pop();
        }
    
protected booleanshouldAddError(java.lang.String propertyName, java.lang.Object value)
Returns false if the value is null, "", or {""} (array of size 1 with a blank element). Returns true otherwise.

param
propertyName the name of the property to check.
param
value the value to error check.
return
false if the value is null, "", or {""}, true otherwise.

        if (value == null) {
            return false;
        }

        if ("".equals(value)) {
            return false;
        }

        if (value instanceof String[]) {
            String[] array = (String[]) value;

            if (array.length == 0) {
                return false;
            }

            if (array.length > 1) {
                return true;
            }

            String str = array[0];

            if ("".equals(str)) {
                return false;
            }
        }

        return true;