3 Replies Latest reply on Sep 10, 2009 1:42 PM by Daniel Wachter

    Inconsistent behaviour of calling messages from code

    Daniel Wachter Newbie


      i have some problems with calling seam messages in my sfsb.
      my sfsb with scope conversation, is called by a quartz job to sending some emails.
      the content of a email is fetched by using the


      function and puttet in a email object from which the xhtml email template get its values from.

      if i make a fresh deploy, everything works as it should.
      but after some times of calling the bean, the content doesn't get found by the messages function.
      (the returned label is the label itself, myLabel)

      if i make a fresh deploy of the application, the problem is solved for some time.
      i already had discussed this problem in another thread, but i think it's better to start a new one.
      (to not hijacking another thread)

      i think there is something wrong with my bean, so i would be very thankful if someone could give a short look at it to find the error:

      my sfsb:

      @TransactionTimeout(5400) // Sets the timeout for this long-running transaction
      public class MailActionImpl implements MailAction {
      private Map<String,String> messages;
      public void createEmail() {
         String subject = messages.get("lbl_email_subject");
         String textHTML = messages.get("lbl_email_textHTML");
         String textPlain = messages.get("lbl_email_textPlain");
         email = new Email(recipient, subject, textHTML, textPlain);     

        • 1. Re: Inconsistent behaviour of calling messages from code
          Tomasz Wilczynski Newbie

          I have run into the same problem a while ago. The problem is that when mailAction is instantiated by Seam, bijection takes place and the bundle is loaded properly. But after server restart, this is just a plain ejb instantiated by timer service (in your case - Quartz). There's no use from @In outside Seam container.

          My solution is: when I need to access the bundle from a component that might live outside Seam context, I use this code:

          @Name( "stringUtils" )
          public class StringUtils {
               public String getBundleMsgForEjb( String bundleKey, Object... arguments ) {
                    if( bundleKey == null ) {
                         return null;
                    try {
                         ResourceBundle resourceBundle = ResourceBundle.getBundle( "messages" );
                         String bundleValue = resourceBundle.getString( bundleKey );
                         if ( bundleValue != null && arguments.length > 0 ) {
                              String rawMsg = bundleValue.replaceAll( "'", "''" );
                              return MessageFormat.format( rawMsg, arguments );
                         } else {
                              return bundleValue;
                    } catch ( MissingResourceException e ) {
                         log.info( "Can't find bundle or bundle value for key: #0. Returning the key.", bundleKey );
                    return bundleKey;

          Please note that you need to place messages_XX.properties directly in jar file, so you probably want to modify your ant script.

          Good luck ;-)

          • 2. Re: Inconsistent behaviour of calling messages from code
            Daniel Wachter Newbie

            Hi Tom

            Thank you for your quick answer.
            I forget to mention, that i have also a view in the seam context, from which i can start the mailAction manually.
            If I start the mailAction manually i got the same problems...

            I don't get the clue because If I login, seam is started and also the messages, isn't it?
            Thanks for helping

            • 3. Re: Inconsistent behaviour of calling messages from code
              Daniel Wachter Newbie

              I just tested as you sugested!

              • If I make a server restart, login into my seam app and call the mailAction, the messages doesn't get fetched!

              • If I make a restart of the application (touch application.ear), login into my seam app, the messages get fetched as they should!

              This is the behaviour explained by Tom! Thank you!

              Perhaps I am to stupid, but I don't understand your explication...

              Why seam isn't started properly, if I make a server restart and login in my seam application?