【问题标题】:JSF Bean Validation with custom text parameters带有自定义文本参数的 JSF Bean 验证
【发布时间】:2014-05-23 12:00:51
【问题描述】:

我创建了一个看起来像这样的验证约束

@Documented
@Constraint(validatedBy = WordValidator.class)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Word {

    String message() default "{com.asd.validator.Word}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * @return size the element must be higher or equal to
     */
    int min() default 0;

    /**
     * @return size the element must be lower or equal to
     */
    int max() default Integer.MAX_VALUE;
}

带有一些验证器。之后,我创建了一个名为 ValidationMessages.properties 的文件,并在 face-config.xml 中创建了一个条目,如下所示:

 <application>
        <message-bundle>ValidationMessages</message-bundle>
    </application>

在 ValidationMessages.properties 我添加了以下条目:

com.asd.validator.Word=The words must have min {0} and max {1} characters.

在 {0} 和 {1} 中,我想添加我的验证约束的最小值和最大值。

如何设置文本参数?必须有一种方法,因为标准 jsf 验证约束具有带有此类文本参数的消息。

【问题讨论】:

    标签: bean-validation


    【解决方案1】:

    你试过了吗:

    The words must have min {min} and max {max} characters.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-13
      • 2019-07-02
      • 2016-10-25
      • 2012-05-05
      • 1970-01-01
      相关资源
      最近更新 更多