OmniFaces Param.validatorAttributes的用法

dar*_*ilz 6 jsf omnifaces

我尝试使用OmniFaces @Param批注注入请求参数。
我还利用其validatorClasses属性来验证参数。最终,这个使用过的验证器需要一个特殊的属性才能起作用,我想通过设置validatorAttributes属性来传递值。不幸的是我不知道如何。该文件提供的描述,但我只是不明白它的权利。

有人可以帮忙吗?

这是一些代码:

    @Inject
    @Param(
            name = "the_param_name",
            validatorClasses = MyFreshValidator.class,
            validatorAttributes = ?
    )
    private MyFreshClass instance;
Run Code Online (Sandbox Code Playgroud)

将同一类的另一个对象提供给验证器将是理想的。

Bal*_*usC 5

它确实确实隐藏在陈列柜中。如果打开CdiParamBean“演示源代码”部分的选项卡,则将通过以下示例找到托管bean的源代码:

// Like <f:viewParam name="text2" value="#{bean.text2}" validatorMessage="..."><f:validateLength minimum="3">
@Inject @Param(
    validatorClasses = LengthValidator.class,
    validatorAttributes = @Attribute(name="minimum", value="3"),
    validatorMessage = "{1}: Value is too too small! Please enter a minimum of 3 characters.")
private String text2;
Run Code Online (Sandbox Code Playgroud)

// Like <f:viewParam name="date" value="#{bean.date}" converterMessage="..."><f:convertDateTime pattern="yyyyMMdd">
@Inject @Param(
    converterClass = DateTimeConverter.class,
    converterAttributes = { @Attribute(name="pattern", value="yyyyMMdd") },
    converterMessage="{1}: \"{0}\" is not the date format we had in mind! Please use the format yyyyMMdd.")
private Date date;
Run Code Online (Sandbox Code Playgroud)

在这里,@Attributeorg.omnifaces.cdi.param.Attribute

我将在将来的版本中改进文档。

  • “值”支持EL。因此,您可以使用`value =“#{bean.property}”`。 (3认同)