Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Bean Validation+CDI+Tomcat:Unexpected exception
PostPosted: Sun Dec 11, 2016 8:33 am 
Newbie

Joined: Sun Dec 11, 2016 8:03 am
Posts: 1
In a JSF application (using Hibernate Validator and the reference implementation of CDI Weld) running on Tomcat 8: Using @Inject in a ConstraintValidator results in a javax.validation.ValidationException: HV000028: Unexpected exception during isValid call.

Elsewhere in the application, CDI works without errors.

The ConstraintValidator looks like:

Code:
public class MyIntervalValidator implements ConstraintValidator<MyInterval, Integer> {

    @Inject
    private Interval interval;

    public void initialize(MyInterval myIntervall) {
    }

    public boolean isValid(Integer i, ConstraintValidatorContext ctx) {

        Integer ceiling;

        ceiling = interval.getCeiling();

        if ((0 <= i) && (i <= ceiling)) {
            return true;
        }

        return false;
    }


I checked the injection: interval is null during the execution of the method isValid.

The Interval:

Code:
@SessionScoped
public class Interval implements Serializable {

    private static final long serialVersionUID = 1L;

    @Min(value = 1)
    private Integer ceiling;

    public Interval() {
        this.ceiling = 1;
    }

    public Integer getCeiling() {
        return ceiling;
    }

    public void setCeiling(Integer ceiling) {
        this.ceiling = ceiling;
    }

}


The context.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<Context>
    <Resource name="BeanManager"
        auth="Container"
        type="javax.enterprise.inject.spi.BeanManager"
        factory="org.jboss.weld.resources.ManagerObjectFactory" />
</Context>


Detail from the web.xml:

Code:
<resource-env-ref>
   <resource-env-ref-name>BeanManager</resource-env-ref-name>
   <resource-env-ref-type>
      javax.enterprise.inject.spi.BeanManager
   </resource-env-ref-type>
</resource-env-ref>


The dependencies:

Code:
         <dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.2.14</version>
     </dependency>
     
     <dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>2.2.14</version>
     </dependency>
     
   <dependency>
         <groupId>javax.servlet</groupId>
         <artifactId>jstl</artifactId>
         <version>1.2</version>
   </dependency>
   

   <dependency>
       <groupId>org.hibernate</groupId>
      <artifactId>hibernate-validator</artifactId>
      <version>5.3.4.Final</version>
       </dependency>
   

   <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-cdi</artifactId>
        <version>5.3.4.Final</version>
       </dependency>
       
   <dependency>
      <groupId>javax.el</groupId>
      <artifactId>javax.el-api</artifactId>
      <version>2.2.4</version>
   </dependency>

   <dependency>
      <groupId>org.glassfish.web</groupId>
      <artifactId>javax.el</artifactId>
      <version>2.2.4</version>
   </dependency>

   <dependency>
       <groupId>org.jboss.weld.servlet</groupId>
       <artifactId>weld-servlet-core</artifactId>
       <version>2.4.1.Final</version>
   </dependency>


Information regarding the environment:

  • Maven
  • Tomcat 8 via Eclipse Neon
  • CDI: weld-servlet-core (empty bean.xml in folder WEB-INF)
  • Bean Validation: hibernate-validator
  • JSF: com.sun.faces

Many thanks for any help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.