当前位置: 首页>>代码示例>>Java>>正文


Java DelegatingValidatorContext类代码示例

本文整理汇总了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());
            }
        }
     }
}
 
开发者ID:umeshawasthi,项目名称:jsr303-validator-plugin,代码行数:37,代码来源:JSR303ValidationInterceptor.java

示例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();

}
 
开发者ID:NCIP,项目名称:caarray,代码行数:12,代码来源:HibernateValidatorTest.java


注:本文中的com.opensymphony.xwork2.validator.DelegatingValidatorContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。