4 Replies Latest reply on Jul 7, 2011 2:17 AM by Martin Frey

    Custom validation messages not being used

    Jonathon Freeman Newbie

      I am using Hibernate validation to validate my form. Here is a segment of my bean:


      public class Client implements Serializable
      {
           @NotEmpty(message="#{messages['errors.client.clientId.empty']}")
           @Length(max=25, message="#{messages['errors.client.clientId.tooLong']}")
           private String clientId;



      In my components.xml I have this:


      <core:resource-loader>
           <core:bundle-names>
                <value>messages</value>
           </core:bundle-names>
      </core:resource-loader>



      And I have a messages_en.properties file that contains:
      errors.client.clientId.empty=You must specify a client ID


      And yet I get this error upon submitting an empty form:
      j_id5:id: Validation Error: Value is required.


      If I add javax.faces.component.UIInput.REQUIRED=value is required into my messages_en.properties file, I receive this error: value is required


      It's basically ignoring the message property on my validation annotations and using javax.faces.component.UIInput.REQUIRED instead.


      Any ideas?

        • 1. Re: Custom validation messages not being used
          Jonathon Freeman Newbie

          After further troubleshooting, it appears that Hibernate validation is not getting invoked. For instance, if I enter in 26 characters (1 character more than max) into the client ID field on the form and submit, I don't get an error! Only JSF validation is working...


          I followed this page exactly, but still nothing.


          Any ideas? There's gotta be something I'm missing here.


          Could it be that I'm not using the rest of Hibernate for managing my entities/beans?

          • 2. Re: Custom validation messages not being used
            Jonathon Freeman Newbie

            Okay... I figured out why Hibernate validation wasn't getting invoked; I had my validation annotations on the private properties. I added them to my getters:


            @NotEmpty(message="Client ID is required")
            @Length(max=25, message="Client ID must be 25 characters or less")
            public String getClientId()
            {
                 return clientId;
            }



            And it works. But now I'm back to the original problem... if I put as the message property in the annotation like so, message="#{messages['errors.client.clientId.tooLong']}", I get this exception when submitting the empty form:


            javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:530)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
            org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
            org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
            org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
            org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
            org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
            org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
            org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
            org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
            org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
            org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
            org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
            org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
            org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
            org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
            org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
            java.lang.Thread.run(Thread.java:595)



            Caused by java.lang.NullPointerException with message: ""


            javax.faces.validator.ValidatorException.<init>(ValidatorException.java:64)
            org.jboss.seam.ui.validator.ModelValidator.validate(ModelValidator.java:46)
            org.richfaces.component.html.HtmlInputText.validateValue(HtmlInputText.java:52)
            javax.faces.component.UIInput.validate(UIInput.java:875)
            javax.faces.component.UIInput.executeValidate(UIInput.java:1072)
            javax.faces.component.UIInput.processValidators(UIInput.java:672)
            javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
            javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
            javax.faces.component.UIForm.processValidators(UIForm.java:235)
            org.ajax4jsf.component.AjaxViewRoot$3.invokeContextCallback(AjaxViewRoot.java:442)
            org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:235)
            org.ajax4jsf.component.AjaxViewRoot.processValidators(AjaxViewRoot.java:458)
            com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
            com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
            com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
            javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:530)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
            org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
            org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
            org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
            org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
            org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
            org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
            org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
            org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
            org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
            org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
            org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
            org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
            org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
            org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
            org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
            java.lang.Thread.run(Thread.java:595)



            • 3. Re: Custom validation messages not being used
              Jonathon Freeman Newbie

              Nevermind... that was from a missing '] in my validation annotation.


              So Hibernate validation is working for everything but the @NotEmpty ones. On those, the JSF validation error (j_id5:id: Validation Error: Value is required.) is shown instead of my Hibernate validation error (Client ID is required).


              Any ideas there?

              • 4. Re: Custom validation messages not being used
                Martin Frey Newbie

                Hi
                I think NotEmpty is a JPA annotation. What if you use NotNull? We are using only this one currently. Additionally we have implemented a string converter which converts empty strings to null values.


                Oh. And we have all validators on the fields. Works without a problem.


                Regards