use of com.opensymphony.xwork2.validator.DelegatingValidatorContext in project struts by apache.
the class VisitorFieldValidator method validateObject.
private void validateObject(String fieldName, Object o, String visitorContext) throws ValidationException {
ValueStack stack = ActionContext.getContext().getValueStack();
stack.push(o);
ValidatorContext validatorContext;
if (appendPrefix) {
ValidatorContext parent = getValidatorContext();
validatorContext = new AppendingValidatorContext(parent, createTextProvider(o, parent), fieldName, getMessage(o));
} else {
ValidatorContext parent = getValidatorContext();
CompositeTextProvider textProvider = createTextProvider(o, parent);
validatorContext = new DelegatingValidatorContext(parent, textProvider, parent);
}
actionValidatorManager.validate(o, visitorContext, validatorContext);
stack.pop();
}
use of com.opensymphony.xwork2.validator.DelegatingValidatorContext in project struts by apache.
the class RepopulateConversionErrorFieldValidatorSupportTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
ValueStack stack = ActionContext.getContext().getValueStack();
MockActionInvocation invocation = new MockActionInvocation();
invocation.setStack(stack);
ActionContext.getContext().withActionInvocation(invocation);
String[] conversionErrorValue = new String[] { "some value" };
Map<String, ConversionData> conversionErrors = ActionContext.getContext().getConversionErrors();
conversionErrors.put("someFieldName", new ConversionData(conversionErrorValue, Integer.class));
conversionErrors.put("xxxsomeFieldName", new ConversionData(conversionErrorValue, Integer.class));
TextProviderFactory tpf = container.getInstance(TextProviderFactory.class);
action = container.inject(ActionSupport.class);
validator1 = new InternalRepopulateConversionErrorFieldValidatorSupport();
validator1.setFieldName("someFieldName");
validator1.setValidatorContext(new DelegatingValidatorContext(action, tpf));
validator2 = new InternalRepopulateConversionErrorFieldValidatorSupport();
validator2.setFieldName("someFieldName");
validator2.setValidatorContext(new DelegatingValidatorContext(action, tpf) {
@Override
public String getFullFieldName(String fieldName) {
return "xxx" + fieldName;
}
});
}
use of com.opensymphony.xwork2.validator.DelegatingValidatorContext in project struts by apache.
the class SimpleActionValidationTest method testMessageKeyIsReturnedIfNoOtherDefault.
public void testMessageKeyIsReturnedIfNoOtherDefault() throws ValidationException {
Validator validator = new ValidatorSupport() {
public void validate(Object object) throws ValidationException {
addActionError(object);
}
};
validator.setValueStack(ActionContext.getContext().getValueStack());
String messageKey = "does.not.exist";
validator.setMessageKey(messageKey);
SimpleAction action = new SimpleAction();
container.inject(action);
ValidatorContext validatorContext = new DelegatingValidatorContext(action, container.getInstance(TextProviderFactory.class));
validator.setValidatorContext(validatorContext);
validator.validate(this);
assertTrue(validatorContext.hasActionErrors());
Collection<String> errors = validatorContext.getActionErrors();
assertEquals(1, errors.size());
assertEquals(messageKey, errors.toArray()[0]);
}
use of com.opensymphony.xwork2.validator.DelegatingValidatorContext in project struts by apache.
the class StringLengthFieldValidatorTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
action = new InternalActionSupport();
container.inject(action);
ValueStack valueStack = ActionContext.getContext().getValueStack();
valueStack.push(action);
validator = new StringLengthFieldValidator();
validator.setFieldName("myField");
validator.setMessageKey("error");
validator.setValidatorContext(new DelegatingValidatorContext(action, container.getInstance(TextProviderFactory.class)));
validator.setMaxLength(5);
validator.setMinLength(2);
validator.setValueStack(valueStack);
}
use of com.opensymphony.xwork2.validator.DelegatingValidatorContext in project struts by apache.
the class StringValidatorTest method testRequiredStringWithNullValue.
public void testRequiredStringWithNullValue() throws Exception {
Equidae equidae = new Equidae();
equidae.setHorse(null);
DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
assertTrue(context.hasFieldErrors());
}
Aggregations