4 Replies Latest reply on Aug 16, 2007 2:53 AM by frippe

    EL-exceptions in email render from async class

    frippe

      I have an asynchronus method sending emails, but I can't get any values to work due to EL-exceptions.

      My class:

      @Name("emailProcessor")
      @AutoCreate
      public class EmailProcessor {
      
       @Asynchronous
       @Transactional
       public QuartzTriggerHandle scheduleSend(@Expiration Date endDate, Company company) {
       for(Person p : company.getPersons()){
       try {
       renderer.render("/mails/reminder.xhtml");
       log.debug("Email sent successfully");
       }
       catch (Exception e) {
       log.debug("Email sending failed: " + e.getMessage());
       e.printStackTrace();
       }
      
      
       }
      
       }
      
      }
      



      And my XHTML-file:
      <m:message xmlns="http://www.w3.org/1999/xhtml"
       xmlns:m="http://jboss.com/products/seam/mail"
       xmlns:h="http://java.sun.com/jsf/html">
      
       <m:from name="Påminnelsemailet" address="admin at two.se" />
       <m:to name="{p.fullName}">{p.email}</m:to>
       <m:subject>Glöm inte. . .</m:subject>
      
       <m:body>
       <p><h:outputText value="Hej {p.name}"/>,<br/>
       Glöm inte att ...
       </p>
       </m:body>
      
      </m:message>


      If I cut out the EL-expressions, the mails are sent successfully.
      I'm not quite sure how to outject the persons to be able to send the mails, anyone got an idea?

      I probably get an RTFM on this one, but I got stuck on this...

        • 1. Re: EL-exceptions in email render from async class
          pmuir

          I don't see any EL in your mail template.

          • 2. Re: EL-exceptions in email render from async class
            frippe

            sorry...
            I pasted the code I was testing. . .

            The correct XHTML should have been

            <m:message xmlns="http://www.w3.org/1999/xhtml"
             xmlns:m="http://jboss.com/products/seam/mail"
             xmlns:h="http://java.sun.com/jsf/html">
            
             <m:from name="Påminnelsemailet" address="admin at two.se" />
             <m:to name="#{p.fullName}">#{p.email}</m:to>
             <m:subject>Glöm inte. . .</m:subject>
            
             <m:body>
             <p><h:outputText value="Hej #{p.name}"/>,<br/>
             Glöm inte att ...
             </p>
             </m:body>
            
            </m:message>



            This code generates EL exceptions on every #{} instance.
            I've tried different approaces to get the values, but it's not clear to me how to solve this problem in a appropriate way.

            Well, hmm I guess it's an NPE, but I still don't get how to outject the data I need...
            16:50:23,812 DEBUG [RaffleProcessor] Email sending failed: null
            16:50:23,828 ERROR [STDERR] java.lang.NullPointerException
            16:50:23,828 ERROR [STDERR] at com.sun.faces.el.ImplicitObjectELResolver.getValue(ImplicitObjectELResolver.java:74)
            16:50:23,828 ERROR [STDERR] at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
            16:50:23,828 ERROR [STDERR] at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
            16:50:23,828 ERROR [STDERR] at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
            16:50:23,843 ERROR [STDERR] at org.jboss.el.parser.AstValue.getValue(AstValue.java:63)
            16:50:23,843 ERROR [STDERR] at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
            16:50:23,843 ERROR [STDERR] at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
            16:50:23,859 ERROR [STDERR] at javax.faces.component.ValueBindingValueExpressionAdapter.getValue(ValueBindingValueExpressionAdapter.java:102)
            16:50:23,859 ERROR [STDERR] at org.jboss.seam.mail.ui.MailComponent.getValue(MailComponent.java:170)
            16:50:23,859 ERROR [STDERR] at org.jboss.seam.mail.ui.MailComponent.getString(MailComponent.java:149)
            16:50:23,859 ERROR [STDERR] at org.jboss.seam.mail.ui.AddressComponent.getName(AddressComponent.java:75)
            16:50:23,859 ERROR [STDERR] at org.jboss.seam.mail.ui.AddressComponent.getInternetAddress(AddressComponent.java:36)
            16:50:23,875 ERROR [STDERR] at org.jboss.seam.mail.ui.RecipientAddressComponent.encodeBegin(RecipientAddressComponent.java:25)
            16:50:23,875 ERROR [STDERR] at org.jboss.seam.ui.util.JSF.renderChild(JSF.java:172)
            16:50:23,875 ERROR [STDERR] at org.jboss.seam.ui.util.JSF.renderChildren(JSF.java:163)
            16:50:23,875 ERROR [STDERR] at org.jboss.seam.mail.ui.UIMessage.encodeChildren(UIMessage.java:165)
            16:50:23,890 ERROR [STDERR] at org.jboss.seam.ui.util.JSF.renderChild(JSF.java:175)
            16:50:23,890 ERROR [STDERR] at org.jboss.seam.ui.util.JSF.renderChildren(JSF.java:163)
            16:50:23,890 ERROR [STDERR] at org.jboss.seam.ui.facelet.FaceletsRenderer.renderFacelet(FaceletsRenderer.java:149)
            16:50:23,890 ERROR [STDERR] at org.jboss.seam.ui.facelet.FaceletsRenderer.render(FaceletsRenderer.java:113)
            16:50:23,890 ERROR [STDERR] at se.two.reminder.actions.EmailProcessor.scheduleSend(EmailProcessor.java:125)
            16:50:23,906 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            16:50:23,906 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            16:50:23,906 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            16:50:23,906 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
            16:50:23,906 ERROR [STDERR] at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
            16:50:23,906 ERROR [STDERR] at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
            16:50:23,921 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
            16:50:23,921 ERROR [STDERR] at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
            16:50:23,921 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            16:50:23,937 ERROR [STDERR] at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
            16:50:23,937 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            16:50:23,937 ERROR [STDERR] at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
            16:50:23,937 ERROR [STDERR] at org.jboss.seam.util.Work.workInTransaction(Work.java:39)
            16:50:23,937 ERROR [STDERR] at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
            16:50:23,953 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            16:50:23,953 ERROR [STDERR] at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
            16:50:23,953 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            16:50:23,953 ERROR [STDERR] at org.jboss.seam.async.AsynchronousInterceptor.aroundInvoke(AsynchronousInterceptor.java:42)
            16:50:23,953 ERROR [STDERR] at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            16:50:23,968 ERROR [STDERR] at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
            16:50:23,968 ERROR [STDERR] at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:155)
            16:50:23,968 ERROR [STDERR] at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:91)
            16:50:23,968 ERROR [STDERR] at se.two.reminder.actions.EmailProcessor_$$_javassist_3.scheduleSend(EmailProcessor_$$_javassist_3.java)
            16:50:23,968 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            16:50:23,984 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            16:50:23,984 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            16:50:23,984 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
            16:50:23,984 ERROR [STDERR] at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
            16:50:23,984 ERROR [STDERR] at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:124)
            16:50:23,984 ERROR [STDERR] at org.jboss.seam.async.AsynchronousInvocation.call(AsynchronousInvocation.java:52)
            16:50:24,000 ERROR [STDERR] at org.jboss.seam.async.Asynchronous.executeInContexts(Asynchronous.java:76)
            16:50:24,000 ERROR [STDERR] at org.jboss.seam.async.Asynchronous.execute(Asynchronous.java:45)
            16:50:24,000 ERROR [STDERR] at org.jboss.seam.async.QuartzDispatcher$QuartzJob.execute(QuartzDispatcher.java:289)
            16:50:24,000 ERROR [STDERR] at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
            16:50:24,015 ERROR [STDERR] at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
            



            Btw...
            I am running on Seam 2.0.0 B1 nightly build 111 - which works nicely in all other aspects :-)


            • 3. Re: EL-exceptions in email render from async class
              pmuir

              Ok, so you aren't outjecting the variable p as far as I can see. There is no magic 'I'm looping over this in Java so it becomes available in EL' . Have you read about sending multiple messages in the reference manual (mail chapter)?

              Combine a ui:repeat with:

              @Asynchronous @Transactional
              public QuartzTriggerHandle scheduleSend(@Expiration Date endDate, Company company) {
               Contexts.getEventContext().set("people", company.getPersons());
               renderer.render("/mails/reminder.xhtml");
              }


              • 4. Re: EL-exceptions in email render from async class
                frippe

                naturally!
                I must have missed that part in chapter 17 (http://docs.jboss.com/seam/2.0.0.B1/reference/en/html/mail.html). I had a backward approach in mind - the one that didn't work.

                After giving myself a good RTFM using your hint, I solved the problem.

                Thanx Pete