use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class BeanValidationInterceptorTest method testModelDrivenActionEmailField.
public void testModelDrivenActionEmailField() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("bean-validation", "modelDrivenAction", null, null);
ModelDrivenAction action = (ModelDrivenAction) baseActionProxy.getAction();
action.getModel().setName("name");
action.getModel().setEmail("notamail");
action.getModel().getAddress().setStreet("street");
baseActionProxy.execute();
Map<String, List<String>> fieldErrors = ((ValidationAware) baseActionProxy.getAction()).getFieldErrors();
assertNotNull(fieldErrors);
assertEquals(1, fieldErrors.size());
assertTrue(fieldErrors.get("email").size() > 0);
assertEquals(fieldErrors.get("email").get(0), "emailNotValid");
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class BeanValidationInterceptorTest method testModelDrivenActionSkipValidationByInterface.
public void testModelDrivenActionSkipValidationByInterface() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("bean-validation", "modelDrivenActionSkipValidationByInterface", null, null);
ModelDrivenAction action = (ModelDrivenAction) baseActionProxy.getAction();
action.getModel().setName(null);
action.getModel().setEmail(null);
action.getModel().getAddress().setStreet(null);
baseActionProxy.execute();
Map<String, List<String>> fieldErrors = ((ValidationAware) baseActionProxy.getAction()).getFieldErrors();
assertNotNull(fieldErrors);
assertEquals(0, fieldErrors.size());
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class BeanValidationInterceptorTest method testModelDrivenActionSuccess.
public void testModelDrivenActionSuccess() throws Exception {
ActionProxy baseActionProxy = actionProxyFactory.createActionProxy("bean-validation", "modelDrivenAction", null, null);
ModelDrivenAction action = (ModelDrivenAction) baseActionProxy.getAction();
action.getModel().setName("name");
action.getModel().setEmail("jogep@apache.org");
action.getModel().getAddress().setStreet("street");
baseActionProxy.execute();
Map<String, List<String>> fieldErrors = ((ValidationAware) baseActionProxy.getAction()).getFieldErrors();
assertNotNull(fieldErrors);
assertEquals(0, fieldErrors.size());
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project entando-core by entando.
the class RedirectMessageInterceptor method after.
/**
* If the result is a redirect then store error and messages in the session.
* @param invocation
* @param validationAware
* @throws java.lang.Exception
*/
protected void after(ActionInvocation invocation, ValidationAware validationAware) throws Exception {
Result result = invocation.getResult();
if (result != null && (result instanceof ServletRedirectResult || result instanceof ServletActionRedirectResult || result instanceof FrontServletActionRedirectResult)) {
HttpServletRequest request = (HttpServletRequest) invocation.getInvocationContext().get(ServletActionContext.HTTP_REQUEST);
HttpSession session = request.getSession();
Collection<String> actionErrors = validationAware.getActionErrors();
if (actionErrors != null && actionErrors.size() > 0) {
session.setAttribute(ACTION_ERRORS_KEY, actionErrors);
}
Collection<String> actionMessages = validationAware.getActionMessages();
if (actionMessages != null && actionMessages.size() > 0) {
session.setAttribute(ACTION_MESSAGES_KEY, actionMessages);
}
Map<String, List<String>> fieldErrors = validationAware.getFieldErrors();
if (fieldErrors != null && fieldErrors.size() > 0) {
session.setAttribute(FIELD_ERRORS_KEY, fieldErrors);
}
}
}
use of com.opensymphony.xwork2.interceptor.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();
}
Aggregations