本文整理匯總了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();
}