org.apache.struts2.json
Class JSONValidationInterceptor
java.lang.Object
com.opensymphony.xwork2.interceptor.AbstractInterceptor
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor
org.apache.struts2.json.JSONValidationInterceptor
- All Implemented Interfaces:
- com.opensymphony.xwork2.interceptor.Interceptor, Serializable
public class JSONValidationInterceptor
- extends com.opensymphony.xwork2.interceptor.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).
If 'struts.validateOnly' is set to false you may want to use JSONActionRedirectResult
.
A request parameter named 'struts.enableJSONValidation' must be set to 'true' to
use this interceptor
If the request has a parameter 'struts.JSONValidation.set.encoding' set to true
the character encoding will NOT be set on the response - is needed in portlet environment
- for more details see issue WW-3237
- See Also:
- Serialized Form
Fields inherited from class com.opensymphony.xwork2.interceptor.MethodFilterInterceptor |
excludeMethods, includeMethods, log |
Method Summary |
protected String |
buildResponse(com.opensymphony.xwork2.ValidationAware validationAware)
|
protected String |
doIntercept(com.opensymphony.xwork2.ActionInvocation invocation)
|
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 |
VALIDATE_ONLY_PARAM
public static final String VALIDATE_ONLY_PARAM
- See Also:
- Constant Field Values
VALIDATE_JSON_PARAM
public static final String VALIDATE_JSON_PARAM
- See Also:
- Constant Field Values
NO_ENCODING_SET_PARAM
public static final String NO_ENCODING_SET_PARAM
- See Also:
- Constant Field Values
DEFAULT_ENCODING
public static final String DEFAULT_ENCODING
- See Also:
- Constant Field Values
JSONValidationInterceptor
public JSONValidationInterceptor()
setValidationFailedStatus
public void setValidationFailedStatus(int validationFailedStatus)
- HTTP status that will be set in the response if validation fails
- Parameters:
validationFailedStatus
-
doIntercept
protected String doIntercept(com.opensymphony.xwork2.ActionInvocation invocation)
throws Exception
- Specified by:
doIntercept
in class com.opensymphony.xwork2.interceptor.MethodFilterInterceptor
- Throws:
Exception
buildResponse
protected String buildResponse(com.opensymphony.xwork2.ValidationAware validationAware)
- Returns:
- JSON string that contains the errors and field errors
Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.