4 Replies Latest reply on Jun 13, 2013 8:47 AM by David Baddeley

    Quartz, Locale and Mail - FacesContext is null

    Frank Bitzer Newbie

      Hi,


      I'm trying to send e-mails from an Quartz scheduled process. The mails contain text from a resource bundle and must be sent in different languages. My classes are as follows:




      @Name("scheduleController")
      @AutoCreate
      public class ScheduleController implements java.io.Serializable { 
      
              @In 
              Processor processor;   
      
              public void scheduleTimer() {
                      
                  //run task every minute
                  String intervalLogs = "0 0/1";
                  processor.createLogs(new Date(), intervalLogs);
               }
      }






      @Name("processor")
      @AutoCreate
      @Scope(ScopeType.APPLICATION)
      public class Processor { 
          
              @In(create = true)
              private Renderer renderer;
      
      
              @In(create=true)
              LocaleSelector localeSelector;
      
              @Asynchronous
              @Transactional
              public QuartzTriggerHandle createLogs(@Expiration Date when, @IntervalCron String interval){
                
                //...
                //Code to get the Locale for this mail (country code is stored in a database
                //...
      
                //try to set locale and to send mail
                localeSelector.setLocale(locale);
                      
                //this is required to confirm/save the selection and force the reload of message bundles!
                localeSelector.select();  //THIS IS THE LINE WHERE IT BREAKS DOWN
      
                renderer.render("/mymail.xhtml");
              }
              
      }



      It crashes in org.jboss.seam.international.LocaleSelector.select(LocaleSelector.java:65) with a NullPointerException. You can view the source of LocaleSelector here:Click


      Obviously, the javax.faces.context.FacesContext.getCurrentInstance() returns null.


      What can I to?