本文整理汇总了Java中com.opensymphony.xwork2.validator.DelegatingValidatorContext类的典型用法代码示例。如果您正苦于以下问题:Java DelegatingValidatorContext类的具体用法?Java DelegatingValidatorContext怎么用?Java DelegatingValidatorContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DelegatingValidatorContext类属于com.opensymphony.xwork2.validator包,在下文中一共展示了DelegatingValidatorContext类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addBeanValidationErrors
import com.opensymphony.xwork2.validator.DelegatingValidatorContext; //导入依赖的package包/类
@SuppressWarnings("nls")
private void addBeanValidationErrors(Set<ConstraintViolation<Object>> constraintViolations, Object action) {
if (constraintViolations != null) {
ValidatorContext validatorContext = new DelegatingValidatorContext(action);
for (ConstraintViolation<Object> constraintViolation : constraintViolations) {
String key = constraintViolation.getMessage();
String message = key;
try {
message = validatorContext.getText(key);
if(convertToUtf8 && StringUtils.isNotBlank(message)) {
message = new String(message.getBytes(convertFromEncoding), "UTF-8");
}
} catch (Exception e) {
LOG.error("Error while trying to fetch message", e);
}
if (isActionError(constraintViolation)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding action error '#0'", message);
}
validatorContext.addActionError(message);
} else {
ValidationError validationError = buildBeanValidationError(constraintViolation, message);
String fieldName = validationError.getFieldName();
if (action instanceof ModelDriven && fieldName.startsWith(ValidatorConstants.MODELDRIVEN_PREFIX)) {
fieldName = fieldName.replace("model.", ValidatorConstants.EMPTY_SPACE);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Adding field error [#0] with message '#1'", fieldName, validationError.getMessage());
}
validatorContext.addFieldError(fieldName, validationError.getMessage());
}
}
}
}
示例2: onSetUp
import com.opensymphony.xwork2.validator.DelegatingValidatorContext; //导入依赖的package包/类
@Before
public void onSetUp() {
this.action = new TestAction();
this.validatorContext = new DelegatingValidatorContext(this.action);
validator = new HibernateValidator();
validator.setValidatorContext(validatorContext);
CaArrayUsernameHolder.setUser(AbstractCaarrayTest.STANDARD_USER);
tx = hibernateHelper.beginTransaction();
}