6 Replies Latest reply on Mar 1, 2006 10:56 PM by andrew.rw.robinson

    Message bundle issues

    andrew.rw.robinson

      Okay, I am trying to make a patch from the hibernate annotations validator to support child objects. One of my objects has the email validator annotation on it. My faces configuration file is setting the message bundle. However, I am getting an error when seam starts. It loads some kind of generic "messages" bundle that I cannot find the .proeprties file for. Wherever this bundle is, it is missing the standard validation messages:

      ERROR 18-02 16:09:17,761 (StandardContext.java:listenerStart:3731) -Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
      java.lang.IllegalArgumentException: could not instantiate ClassValidator
       at org.hibernate.validator.ClassValidator.createValidator(ClassValidator.java:257)
       at org.hibernate.validator.ClassValidator.createMemberValidator(ClassValidator.java:217)
       at org.hibernate.validator.ClassValidator.initValidator(ClassValidator.java:140)
       at org.hibernate.validator.ClassValidator.<init>(ClassValidator.java:89)
       at org.hibernate.validator.ClassValidator.createChildValidator(ClassValidator.java:172)
       at org.hibernate.validator.ClassValidator.initValidator(ClassValidator.java:142)
       at org.hibernate.validator.ClassValidator.<init>(ClassValidator.java:89)
       at org.hibernate.validator.ClassValidator.createChildValidator(ClassValidator.java:177)
       at org.hibernate.validator.ClassValidator.initValidator(ClassValidator.java:142)
       at org.hibernate.validator.ClassValidator.<init>(ClassValidator.java:89)
       at org.hibernate.validator.ClassValidator.<init>(ClassValidator.java:78)
       at org.jboss.seam.Component.initValidator(Component.java:218)
       at org.jboss.seam.Component.<init>(Component.java:185)
       at org.jboss.seam.Component.<init>(Component.java:142)
       at org.jboss.seam.Component.<init>(Component.java:137)
       at org.jboss.seam.Component.<init>(Component.java:132)
       at org.jboss.seam.init.Initialization.addComponent(Initialization.java:244)
       at org.jboss.seam.init.Initialization.addComponents(Initialization.java:225)
       at org.jboss.seam.init.Initialization.init(Initialization.java:93)
       at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:30)
       at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3727)
       at org.apache.catalina.core.StandardContext.start(StandardContext.java:4162)
       at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
       at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
       at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
       at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
       at org.apache.catalina.core.StandardService.start(StandardService.java:450)
       at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
       at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
       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:585)
       at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275)
       at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
      Caused by: java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key validator.email
       at java.util.ResourceBundle.getObject(ResourceBundle.java:326)
       at java.util.ResourceBundle.getString(ResourceBundle.java:286)
       at org.hibernate.validator.ClassValidator.replace(ClassValidator.java:479)
       at org.hibernate.validator.ClassValidator.createValidator(ClassValidator.java:252)
       ... 34 more
      Feb 18, 2006 4:09:17 PM org.apache.catalina.core.StandardContext start


      Earlier in the startup log I saw:
      INFO 18-02 16:08:39,738 (Component.java:<init>:168) -Component: resourceBundle, scope: APPLICATION, type: JAVA_BEAN, class: org.jboss.seam.core.ResourceBundle
      INFO 18-02 16:08:39,832 (Component.java:<init>:168) -Component: org.jboss.seam.debug.introspector, scope: EVENT, type: JAVA_BEAN, class: org.jboss.seam.debug.Introspector
      INFO 18-02 16:08:55,009 (ResourceBundle.java:loadBundle:58) -loaded resource bundle: messages


      1) Why is seam not finding my bundle?
      2) Why is there no "validator.email" key in the default bundle

      FYI: section from faces config:


      Thanks!
      <application>
       <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
       <locale-config>
       <default-locale>en</default-locale>
       </locale-config>
       <message-bundle>DefaultMessages</message-bundle>
       </application>


        • 1. Re: Message bundle issues
          epbernard

          This was a classloader issue. I've fixed the issue in Hibernate Anntotations CVS.
          Now the Thread context CL is used before anything else to load the resource bundle.

          • 2. Re: Message bundle issues
            andrew.rw.robinson

            There is an additional complexity to this. It seems that on loading, seam looks for the validation messages in "messages.properties", but during runtime, it looks at "ValidatorMessages.properties". To get it working, I had to use the concat ant task to concat ValidatorMessages.properties to the end of my messages.properties.

            • 3. Re: Message bundle issues
              epbernard

              Do you have a warn message somewhere telling you

              Serializing a ClassValidator with a not serializable ResourceBundle: ResourceBundle ignored
              from the ClassValidator category?

              • 4. Re: Message bundle issues
                epbernard

                Oh, Seam initialize the validator to use message.properties
                But the Hibernate Validator Events no not use such things, so if the exception InvalidStateException comes from ValidateEventListener.validate() then that explains

                • 5. Re: Message bundle issues
                  gavin.king

                  Is there something we need to do here to make this easier to use?

                  • 6. Re: Message bundle issues
                    andrew.rw.robinson

                    It would be "fixed" if the ClassValidator is never passed a resource bundle (in that case, it will always use "ValidatorMessage.properties"), or if it is always passed a bundle. From what I saw in the review of the code is that during initialization ClassValidator is passed the messages bundle, but during iterception it isn't passed a bundle and that is why the messages have to be in both.