Search in sources :

Example 1 with ValidationAware

use of com.opensymphony.xwork2.ValidationAware in project qi4j-sdk by Qi4j.

the class ConstraintViolationInterceptor method intercept.

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    ActionContext invocationContext = invocation.getInvocationContext();
    ValueStack stack = invocationContext.getValueStack();
    Object action = invocation.getAction();
    if (action instanceof ValidationAware) {
        ValidationAware va = (ValidationAware) action;
        HashMap<Object, Object> propertyOverrides = new HashMap<Object, Object>();
        for (Map.Entry<String, FieldConstraintViolations> fieldViolations : fieldConstraintViolations(invocationContext).entrySet()) {
            addConstraintViolationFieldErrors(stack, va, fieldViolations.getKey(), fieldViolations.getValue());
            propertyOverrides.put(fieldViolations.getKey(), getOverrideExpr(invocation, fieldViolations.getValue()));
        }
        // if there were some errors, put the original (fake) values in place right before the result
        if (!propertyOverrides.isEmpty()) {
            overrideActionValues(invocation, stack, propertyOverrides);
        }
    }
    return invocation.invoke();
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack) HashMap(java.util.HashMap) ValidationAware(com.opensymphony.xwork2.ValidationAware) ActionContext(com.opensymphony.xwork2.ActionContext) Collections.emptyMap(java.util.Collections.emptyMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ActionContext (com.opensymphony.xwork2.ActionContext)1 ValidationAware (com.opensymphony.xwork2.ValidationAware)1 ValueStack (com.opensymphony.xwork2.util.ValueStack)1 Collections.emptyMap (java.util.Collections.emptyMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1