10 Replies Latest reply on Mar 25, 2010 10:44 AM by Alexander Katzmaier

    A problem with @Email annotation

    Wang Ruifeng Newbie

      When I submit the form  leave the email field null, I receive the debug page and the invalidStateException.


      22:02:52,401 FATAL [application] org.hibernate.validator.InvalidStateException: validation failed for: org.mytest.entitybeans.Student
      javax.faces.el.EvaluationException: org.hibernate.validator.InvalidStateException: validation failed for: org.mytest.entitybeans.Student
              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
              at javax.faces.component.UICommand.broadcast(UICommand.java:383)
              at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:184)
              at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:162)
              at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:350)
              at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
              at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: org.hibernate.validator.InvalidStateException: validation failed for: org.mytest.entitybeans.Student
              at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:143)
              at org.hibernate.validator.event.ValidateEventListener.onPreInsert(ValidateEventListener.java:167)
              at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:156)
              at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:49)
              at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
              at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
              at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
              at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
              at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:296)
              at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:90)
              at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:85)
              at org.mytest.session.beans.StudentHome.persist(StudentHome.java:36)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
              at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.persistence.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:48)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:65)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
              at org.jboss.seam.util.Work.workInTransaction(Work.java:40)
              at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
              at org.mytest.session.beans.StudentHome_$$_javassist_1.persist(StudentHome_$$_javassist_1.java)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
              at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
              at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
              at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
              at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
              ... 46 more
      22:02:52,402 WARN  [lifecycle] #{studentHome.persist}: org.hibernate.validator.InvalidStateException: validation failed for: org.mytest.entitybeans.Student
      javax.faces.FacesException: #{studentHome.persist}: org.hibernate.validator.InvalidStateException: validation failed for: org.mytest.entitybeans.Student
              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:107)
              at javax.faces.component.UICommand.broadcast(UICommand.java:383)
              at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:184)
              at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:162)
              at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:350)
              at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
              at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: javax.faces.el.EvaluationException: org.hibernate.validator.InvalidStateException: validation failed for: org.mytest.entitybeans.Student
              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
              ... 45 more
      Caused by: org.hibernate.validator.InvalidStateException: validation failed for: org.mytest.entitybeans.Student
              at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:143)
              at org.hibernate.validator.event.ValidateEventListener.onPreInsert(ValidateEventListener.java:167)
              at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:156)
              at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:49)
              at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
              at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
              at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
              at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
              at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:296)
              at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:90)
              at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:85)
              at org.mytest.session.beans.StudentHome.persist(StudentHome.java:36)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
              at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.persistence.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:48)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:65)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
              at org.jboss.seam.util.Work.workInTransaction(Work.java:40)
              at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
              at org.mytest.session.beans.StudentHome_$$_javassist_1.persist(StudentHome_$$_javassist_1.java)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
              at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
              at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
              at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
              at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
              ... 46 more


      Student.java


      @Entity
      public class Student extends User implements Serializable {
           
          private String school_id;
          private String email;
          
          @Id
          @NotNull
          @Pattern(regex="[0-9]{8}",message="#{messages['myVlidator.school_id']}")
          public String getSchool_id() {
              return school_id;
          }
          public void setSchool_id(String school_id) {
              this.school_id = school_id;
          }
          
          @Email(message="#{messages['myValidator.email']}")
          public String getEmail() {
              return email;
          }
          public void setEmail(String email) {
              this.email = email;
          }
             
      }



      register.xhtml


      <rich:panel>
      ......
      <s:decorate id="emailDecoration" template="layout/edit.xhtml">
                      <ui:define name="label">#{messages.email}</ui:define>
                      <h:inputText id="email" value="#{student.email}">
                          <a4j:support event="onblur"reRender="emailDecoration" bypassUpdates="true"/>
                      </h:inputText>
      </s:decorate>
      ......
      </rich:panel>
      <h:commandButton id="register" 
                                     value="#{messages.register}" 
                                   action="#{studentHome.persist}"
                              rendered="#{!studentHome.managed}"/>                   
      


      StudentHome.java


      @Name("studentHome")
      public class StudentHome extends EntityHome<Student> {
      
          @RequestParameter 
          String school_id;
          
          @Override
          public Object getId() { 
              if (school_id==null) {
                  return super.getId();
              }
              else {
                  return school_id;
              }
          }
          
          @Override @Begin
          public void create() {
              super.create();
          }
          
          @Override
          public String persist() {
              if(getInstance().getPassword().equals(getInstance().getRepassword())){            
                  return super.persist();
              }
              else{
                  FacesMessages.instance().add("#{messages['myValidator.repassword']}");
                  return null;
              }
          }
         
          @Factory("student")
          public Student initStudent() { 
              return getInstance();
          }
          
          @Override
          public String getCreatedMessage() {
              return "New student #{student.name} created";
          }
            
      }


        • 1. Re: A problem with @Email annotation
          Wang Ruifeng Newbie

          I saw the source of @Email annotation.
          The core code is:


          public boolean isValid(Object value) {
                    if ( value == null ) return true;
                    if ( !( value instanceof String ) ) return false;
                    String string = (String) value;
                          if ( string.length() == 0 ) return true;
                          Matcher m = pattern.matcher( string );
                    return m.matches();
          }



          If the value is null,it returns true.
          But why I leave the field empty when I submit the form.I got invalidStateException.

          • 2. Re: A problem with @Email annotation
            Wang Ruifeng Newbie

            Sorry,I forgot the User code.


            User.java



            @MappedSuperclass
            public abstract class User {
                
                private String name;
                private String password;
                private String repassword;    
                private Date birthday;
            
                @NotEmpty
                @Length(min=2,max=4,message="#{messages['myValidator.name']}")
                public String getName() {
                    return name;
                }
                public void setName(String name) {
                    this.name = name;
                }
            
                @NotNull
             @Length(min=6,max=16,message="#{messages['myValidator.password']}")
                public String getPassword() {
                    return password;
                }
                public void setPassword(String password) {
                    this.password = password;
                }
            
                @Transient
                public String getRepassword() {
                    return repassword;
                }
                public void setRepassword(String repassword) {
                    this.repassword = repassword;
                }    
            
                @Temporal(TemporalType.DATE)
                public Date getBirthday() {
                    return birthday;
                }
                public void setBirthday(Date birthday) {
                    this.birthday = birthday;
                }    
            
            }


            • 3. Re: A problem with @Email annotation
              Marcus Popetz Newbie

              When you submit a form, the value is an empty string which is not permitted.


              I have extended validators just to have add a require flag such that it can pass on an empty string too.  Wish there was an easier way but I have not found one yet.


              Anyone else found an easier way?


              -mp

              • 4. Re: A problem with @Email annotation
                Fernando Montaño Expert

                What is going on is that Hibernate Validator which is bundled on JBoss 4.2.2 is not the latest one (server/default/lib/hibernate-annotations.jar).


                I reported the problem you found the last year,  and it is currently fixed as you can see on Hibernate Validator Issue (As you know).


                Don't know if JBoss Server will update the library in the next versions, but you have two options:


                a) Udpdate the JBoss hibernate libaries manually.


                b) Write your own @Email validator.


                I choose b) in the meantime.



                HTH.


                • 6. Re: A problem with @Email annotation
                  Wang Ruifeng Newbie

                  Where I can found the hibernate-validator libaries?
                  I searched this path /opt/jboss-4.2.2.GA/server/default/lib,but i can't find hibernate-validator.jar.

                  • 7. Re: A problem with @Email annotation
                    Fernando Montaño Expert

                    This is another thing I can't understand, but it is inside hibernate-annotations.jar (.../server/default/lib).


                    So, if you want to upgrade the hibernate-validator you must hack such a jar file.

                    • 8. Re: A problem with @Email annotation
                      Pete Muir Master

                      Between versions of Hibernate Annotations, Hibernate Validator was split out into its own project.

                      • 9. Re: A problem with @Email annotation
                        Chris Simons Expert

                        What do you all recommend for resolving this issue?


                        1) Replace hibernate-annotations.jar in our JBoss server/lib directory?
                        2) Work around the @Email issue by using @Pattern or similar?
                        3) Anything else?


                        Thanks.

                        • 10. Re: A problem with @Email annotation
                          Alexander Katzmaier Newbie

                          I have modified my getter and it works for me:


                          @Column
                          @Email(message="#{messages['validator.email']}")
                          public String getEmail() {
                              // hibernate email validator causes an error when string is empty
                              if (email != null && email.equals("")) {
                                  return null;
                              }
                              return email;
                          }