2 Replies Latest reply on Dec 15, 2010 10:27 AM by gz5737

    help with email & EL in @Asynchronous method

    dpruitt.dpruitt.bitwiseengineering.com

      Hi,


      I have an asynchronous handler that searches a db table and sends email. That part is working great, however I want to pass some of that info into the rendered email via seam EL. The db query works, the player.firstName info is correct I just can't get it transferred into the rendered text of the email. I know that the info has to be in the seam context so I tried to outject it without any joy. I would greatly appreciate any suggestions.


      thanks


      dp





      timer handler (NewHandHandler.java)



      package org.bitwise.blackbox.session.admin;
      
      import java.util.*;
      import javax.ejb.Stateless;
      import javax.persistence.*;
      import org.jboss.seam.annotations.async.*;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.AutoCreate;
      import org.jboss.seam.log.Log;
      //import javax.ejb.Timer;
      import org.jboss.seam.faces.Renderer;
      import org.bitwise.blackbox.entity.Hand;
      import org.bitwise.blackbox.entity.Player;
      
      
      @Stateless
      @Name("newHandHandler")
      @AutoCreate
      public class NewHandHandler implements TimerHandLocal {
      
           //@In(create = true) Timer timer;
          @Logger private Log log;
           
          @In(create = true)
          private Renderer renderer;
          
          @In(value="#{entityManager}")
          EntityManager em;
      
          @Out
          private Player player;
          
          private List<Hand> hands;
           
          @Asynchronous
           public void processNewHands(@IntervalDuration Long interval)
           {
             // implement your business logic here
             log.info("processNewHand()");
      
             List<Hand> results = em.createQuery("select h from Hand as h where h.status = 'new'")
                                    .setMaxResults(25)
                                    .getResultList();
             hands = results;
             
             Iterator it = hands.iterator();
             while (it.hasNext() )
             {
                  Hand hand = (Hand)it.next();
                  
                  //check for player #1
                  player = hand.getPlyr0Id();
                  if (player != null)
                  {
                      renderer.render("/NewVideoMail.xhtml");
                       log.info("player1:" + player.getEmail());
                  }
             }
      
              //return timer; //note that return value is completely ignored
           }
           
      }







      email template (NewVideoMail.xhtml)



      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <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"
                 importance="normal">
         
         <m:header name="X-Component-By" value="blackbox"/>        
         <m:from name="Don Pruitt" address="dpruitt@bitwiseengineering.com"/>
         <m:to name="Don Pruitt">
            dpruitt@windstream.net
         </m:to>
         <m:subject>new blackbox video</m:subject>
         <m:body>
            <p>Dear #{player.firstName},</p>
            <p>Please note that you have new game play video at
            <a href="http://www.blackbox.com/">
               http://www.blackbox.com/
            </a>.</p>
            <p>Regards,</p>
            <p>Fred</p>
         </m:body>
      </m:message>