【问题标题】:Hibernate Validation doesn't display custom error messages in JSF 2Hibernate Validation 在 JSF 2 中不显示自定义错误消息
【发布时间】:2011-11-03 12:36:05
【问题描述】:

我在 JSF 2 和 Spring 中使用休眠验证(4.2.0 Final) 这是我的配置:

1- applicationContext:

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
    <list>

    <value>classpath:messages/ValidationMessages</value>
    <value>classpath:messages/application</value>

    </list>
    </property>
    <property name="defaultEncoding" value="UTF-8"/>
    </bean> 

2- faces-config.xml:

<resource-bundle>
           <base-name>messages.ValidationMessages</base-name>
        </resource-bundle>

当尝试使用以下内容时:

@NotBlank(message = "{name.required}")
private String name;

它不起作用,它不显示来自属性文件的消息,它显示 {name.required}

请告知为什么它不起作用。

【问题讨论】:

  • AFAIR hibernate-validator 总是在类路径的根目录中寻找 ValidationMessages。我建议把它移到那里。
  • 它已经在类路径中,我认为我缺少其他配置。
  • 我说的是 类路径的根,因为在您的示例中,ValidationMessagesmessage 目录中。
  • 啊哈,知道了,我会试试的。

标签: spring jsf-2 bean-validation hibernate-validator


【解决方案1】:

问题是 ValidationMessages.properties 不直接在类路径下,当我将它移动到类路径下时,我将它放在类路径中的消息文件夹中现在直接可以正常使用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 2014-09-11
    相关资源
    最近更新 更多