當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。