org.apache.struts2.interceptor.validation
Class JSONValidationInterceptor

java.lang.Object
  extended by com.opensymphony.xwork2.interceptor.AbstractInterceptor
      extended by com.opensymphony.xwork2.interceptor.MethodFilterInterceptor
          extended by org.apache.struts2.interceptor.validation.JSONValidationInterceptor
All Implemented Interfaces:
Interceptor, Serializable

public class JSONValidationInterceptor
extends MethodFilterInterceptor

Serializes validation and action errors into JSON. This interceptor does not perform any validation, so it must follow the 'validation' interceptor on the stack.

This stack (defined in struts-default.xml) shows how to use this interceptor with the 'validation' interceptor

 <interceptor-stack name="jsonValidationWorkflowStack">
      <interceptor-ref name="basicStack"/>
      <interceptor-ref name="validation">
            <param name="excludeMethods">input,back,cancel</param>
      </interceptor-ref>
      <interceptor-ref name="jsonValidation"/>
      <interceptor-ref name="workflow"/>
 </interceptor-stack>
 

If 'validationFailedStatus' is set it will be used as the Response status when validation fails.

If the request has a parameter 'struts.validateOnly' execution will return after validation (action won't be executed).

A request parameter named 'enableJSONValidation' must be set to 'true' to use this interceptor

See Also:
Serialized Form

Field Summary
private static Logger LOG
           
private static String VALIDATE_JSON_PARAM
           
private static String VALIDATE_ONLY_PARAM
           
private  int validationFailedStatus
           
 
Fields inherited from class com.opensymphony.xwork2.interceptor.MethodFilterInterceptor
excludeMethods, includeMethods, log
 
Constructor Summary
JSONValidationInterceptor()
           
 
Method Summary
private  String buildArray(Collection<String> values)
           
protected  String buildResponse(ValidationAware validationAware)
           
protected  String doIntercept(ActionInvocation invocation)
          Subclasses must override to implement the interceptor logic.
 void setValidationFailedStatus(int validationFailedStatus)
          HTTP status that will be set in the response if validation fails
 
Methods inherited from class com.opensymphony.xwork2.interceptor.MethodFilterInterceptor
applyInterceptor, getExcludeMethodsSet, getIncludeMethodsSet, intercept, setExcludeMethods, setIncludeMethods
 
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
 

Field Detail

LOG

private static final Logger LOG

VALIDATE_ONLY_PARAM

private static final String VALIDATE_ONLY_PARAM
See Also:
Constant Field Values

VALIDATE_JSON_PARAM

private static final String VALIDATE_JSON_PARAM
See Also:
Constant Field Values

validationFailedStatus

private int validationFailedStatus
Constructor Detail

JSONValidationInterceptor

public JSONValidationInterceptor()
Method Detail

setValidationFailedStatus

public void setValidationFailedStatus(int validationFailedStatus)
HTTP status that will be set in the response if validation fails

Parameters:
validationFailedStatus -

doIntercept

protected String doIntercept(ActionInvocation invocation)
                      throws Exception
Description copied from class: MethodFilterInterceptor
Subclasses must override to implement the interceptor logic.

Specified by:
doIntercept in class MethodFilterInterceptor
Parameters:
invocation - the action invocation
Returns:
the result of invocation
Throws:
Exception

buildResponse

protected String buildResponse(ValidationAware validationAware)
Returns:
JSON string that contains the errors and field errors

buildArray

private String buildArray(Collection<String> values)


Copyright © 2000-2009 Apache Software Foundation. All Rights Reserved.