3 Replies Latest reply on Dec 18, 2008 3:13 AM by sebdoncker

    Localization and @WebService

    torakuma

      Hi-


      My custom messages on my entity bean aren't being localized when invoked from a bean using @WebService.  Does anyone know if there are localization issues when using @WebService and Hibernate validation?


      Message config from components.xml...



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




      The entity bean...



          @AssertTrue(message = "{someComplexTestFailureMessage}")
          public boolean hasGoodAttributes() {
              return someComplexCheck();
          }



      Localization from the web app works just fine when I manually call the Hibernate validators (It uses EntityHome by the way). 


      If I try to use the same EntityHome from my @WebService bean, an InvalidStateException is thrown (which I expect) but the InvalidValue's message is not localized.



      // The call below returns the string '{someComplexTestFailureMessage}'
      // not the evaluated localized value
      invalidValue.getMessage();



      What's really interesting is that the standard validation messages work just fine.  For example, when I use the Length validator as shown below, I see a properly localized message for that.



          @org.hibernate.validator.Length(min = 2, max = 15)
          public String getSomeValue() {
              return someValue;
          }



      Also, if i call ResourceBundle.getInstance() and loop through the keys, I don't see any of my keys that I had defined by using core:bundle-names. I do see the standard ones from messages however.



      Has anyone else seen this (or have a suggestion)?


      Thanks in advance-


      D

        • 1. Re: Localization and @WebService
          torakuma

          I did some more research and it is looking like Seam is not providing its resourceBundle to Hibernate when it is running from a class inside the jar.  My class that uses the @WebService is in the jar, not the war.  To test this, I made a ValidatorMessages.properties and Hibernate picked it up just fine.


          In the war, however, Hibernate is properly using the resourceBundle configured in components.xml.


          So I guess the question is...


          Is there something special I need to do to get Seam to provide its resourceBundle to Hibernate when validating a class NOT in the war?






          • 2. Re: Localization and @WebService
            sebdoncker

            It's not just for Hibernate.


            I have exactly the same problem with this code in a WebService in a jar :


            Messages.instance().get("some message key");
            



            If someone has an answer ???


            Thanks in advance


            Seb

            • 3. Re: Localization and @WebService
              sebdoncker

              I found a solution.



              1. I put my i18n properties files in the jar

              2. then I have removed the <core:resource-loader><core:bundle-names> part from the components.xml in the WEB-INF of my war.

              3. I create a simple ResourceLoader class to found my properties files :



              @Scope(ScopeType.STATELESS)
              @BypassInterceptors
              @Install(precedence=Install.APPLICATION)
              @Name("org.jboss.seam.core.resourceLoader")
              public class WSResourceLoader extends ResourceLoader {
                   
                   @Override
                   public String[] getBundleNames() {
                        String[] base = super.getBundleNames();
                        
                        String[] bundles = new String[base.length + 2];
                             
                        for(int i = 0, nb = base.length; i< nb; i++)
                             bundles[i] = base[i];
                        int i = base.length;
              
                        bundles[i++] = "/i18n/messages";
                        bundles[i++] = "/i18n/general";
                             
                        return bundles;
                   }
              }
              



              And now, in my web services (in the jar) or in the xhtml (seam) files, the messages bundles are well loaded.


              I don't know if there is a simpler way to do that, but this one does the job !


              If anyone has comments on that ?


              Seb