【问题标题】:Using bean validation (JSR 303) in JSF2 - Primefaces application在 JSF2 中使用 bean 验证 (JSR 303) - Primefaces 应用程序
【发布时间】:2012-06-17 15:36:46
【问题描述】:

我正在尝试将使用休眠验证器的 bean 验证集成到我的 Web 应用程序中:
- tomcat 7 上的 Hibernate-spring-jsf2-primefaces3
我在 Netbeans 中的类路径中添加了以下 jar 文件:hibernate-validator.jar 和 validation-api.jar。

在 pojo 类中,我为 Size 添加了注解:

@Size(min=4, message="Min 4 chars!")
private String name;

在我写的 .xhtml 页面中:

<p:inputText title="name" id="name" value="#{myBean.user.name}"></p:inputText>
<p:message for="name" />

运行我的应用程序并在名称字段中输入少于 4 个字符后,我看不到任何消息,处理继续并将数据保存到数据库。 在我看到的日志输出中:

14 juin 2012 14:55:03 org.apache.myfaces.view.facelets.tag.jsf.ComponentTagHandlerDelegate shouldAddEnclosingValidator
ATTENTION: Bean validation is not available on the classpath, thus the BeanValidator will not be added for the component org.primefaces.component.inputtext.InputText@1f3fd22
14 juin 2012 14:55:04 javax.faces.component._ExternalSpecifications isBeanValidationAvailable
INFO: MyFaces Bean Validation support disabled

我想知道是否有任何我必须设置的配置,或者我必须添加的任何 jar 文件。

【问题讨论】:

    标签: jsf netbeans annotations primefaces bean-validation


    【解决方案1】:

    已解决,
    我必须添加所需的 jar 文件:jboss-logging-3.1.0.CR2.jar 从 hibernate-validator zip 文件到 lib 目录。
    我认为 log4j 足以记录日志,但我错了。

    【讨论】:

      【解决方案2】:

      这个问题之前已经回答过了。

      如果你想使用 bean 验证,你需要一个 Java EE 容器。 Tomcat 只是一个 servlet 容器,因此您需要额外的库。

      Not getting JSR303 annotations to work with Tomcat 7

      【讨论】:

        猜你喜欢
        • 2013-11-23
        • 2017-09-30
        • 2015-01-10
        • 1970-01-01
        • 2012-05-12
        • 1970-01-01
        • 2011-07-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多