use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class ParametersInterceptor method notifyDeveloperParameterException.
protected void notifyDeveloperParameterException(Object action, String property, String message) {
String developerNotification = "Unexpected Exception caught setting '" + property + "' on '" + action.getClass() + ": " + message;
if (action instanceof TextProvider) {
TextProvider tp = (TextProvider) action;
developerNotification = tp.getText("devmode.notification", "Developer Notification:\n{0}", new String[] { developerNotification });
}
LOG.error(developerNotification);
if (action instanceof ValidationAware) {
// see https://issues.apache.org/jira/browse/WW-4066
Collection<String> messages = ((ValidationAware) action).getActionMessages();
messages.add(message);
((ValidationAware) action).setActionMessages(messages);
}
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class ShortRangeValidatorTest method testRangeValidation.
public void testRangeValidation() {
HashMap<String, Object> params = new HashMap<>();
params.put("shortFoo", "200");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
Map errors = ((ValidationAware) proxy.getAction()).getFieldErrors();
List errorMessages = (List) errors.get("shortFoo");
assertEquals(1, errorMessages.size());
String errorMessage = (String) errorMessages.get(0);
assertNotNull(errorMessage);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class SimpleActionValidationTest method testMessageKey.
public void testMessageKey() {
HashMap<String, Object> params = new HashMap<>();
params.put("foo", "200");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
ValueStack stack = ActionContext.getContext().getValueStack();
stack.getActionContext().withLocale(Locale.US);
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
Map<String, List<String>> errors = ((ValidationAware) proxy.getAction()).getFieldErrors();
List<String> fooErrors = errors.get("foo");
assertEquals(1, fooErrors.size());
String errorMessage = fooErrors.get(0);
assertNotNull(errorMessage);
assertEquals("Foo Range Message", errorMessage);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class SimpleActionValidationTest method testParamterizedMessage.
public void testParamterizedMessage() {
HashMap<String, Object> params = new HashMap<>();
params.put("bar", "42");
HashMap<String, Object> extraContext = new HashMap<>();
extraContext.put(ActionContext.PARAMETERS, HttpParameters.create(params).build());
try {
ActionProxy proxy = actionProxyFactory.createActionProxy("", MockConfigurationProvider.VALIDATION_ACTION_NAME, null, extraContext);
proxy.execute();
assertTrue(((ValidationAware) proxy.getAction()).hasFieldErrors());
Map<String, List<String>> errors = ((ValidationAware) proxy.getAction()).getFieldErrors();
List<String> barErrors = errors.get("bar");
assertEquals(1, barErrors.size());
String errorMessage = barErrors.get(0);
assertNotNull(errorMessage);
assertEquals("bar must be between 6 and 10, current value is 42.", errorMessage);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of com.opensymphony.xwork2.interceptor.ValidationAware in project struts by apache.
the class ConversionErrorFieldValidatorTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
ValueStack stack = ActionContext.getContext().getValueStack();
Map<String, ConversionData> conversionErrors = new HashMap<>();
conversionErrors.put("foo", new ConversionData("bar", Integer.class));
ActionContext.of(stack.getContext()).withConversionErrors(conversionErrors).bind();
validator = new ConversionErrorFieldValidator();
validationAware = new ValidationAwareSupport();
DelegatingValidatorContext validatorContext = new DelegatingValidatorContext(validationAware, container.getInstance(TextProviderFactory.class));
stack.push(validatorContext);
validator.setValidatorContext(validatorContext);
validator.setFieldName("foo");
validator.setValueStack(ActionContext.getContext().getValueStack());
assertEquals(0, validationAware.getFieldErrors().size());
}
Aggregations