-
1. Re: Async e-mail on registration
cash1981 Aug 10, 2010 3:48 AM (in response to mmaia)I wrote this a while back.
Maybe it can help you out.My guess is that your user object is null.
When you are making Asynchronous calls you have to set it in the asynchronous context.
Thus you should set the user in your enviaEmailAtivacao() method like this:public void enviaEmailAtivacao() { Contexts.getConversationContext().set("user",user); }
-
2. Re: Async e-mail on registration
cash1981 Aug 10, 2010 3:49 AM (in response to mmaia)I saved too fast. Correct code would be:
@Asynchronous public void enviaEmailAtivacao() { Contexts.getConversationContext().set("user",user); log.debug("Entrou no EmailRenderer.enviaEmailAtivacao"); renderer.render("/emailAtivacao.xhtml"); }
-
3. Re: Async e-mail on registration
kapitanpetko Aug 10, 2010 5:15 AM (in response to mmaia)There is no such thing as a conversation (or session for that matter) inside your asynchronous call. While the above code may work, it is misleading. Use event context instead. Cf, the Seam mail example application:
@Name("asynchronousMailProcessor") @AutoCreate public class AsynchronousMailProcessor { private static final LogProvider log = Logging.getLogProvider(AsynchronousMailProcessor.class); @Asynchronous public void scheduleSend(@Duration long delay, Person person) { try { Contexts.getEventContext().set("person", person); Renderer.instance().render("/simple.xhtml"); } catch (Exception e) { log.error("Error scheduling send #0",e); } } }
Using JMS for this may get into more trouble, so stick with async calls :)
-
4. Re: Async e-mail on registration
mmaia Aug 13, 2010 11:47 PM (in response to mmaia)Hi,
sorry for taking so long to provide feedback! Just now had the opportunity to get back to this.
You got it perfectly. It's all working now.
Just took a look at your mentioned article and it really clarified things for me. Thank you.
I have tried using timer-service persistence and was not able to. So I am using quartz instead.
On componentxs.xml
<async:quartz-dispatcher/>
Also fixed my implementation to:
@Asynchronous public void enviaEmailAtivacao(User user) { Contexts.getConversationContext().set("user", user); log.debug("Entrou no EmailRenderer.enviaEmailAtivacao"); renderer.render("/emailAtivacao.xhtml"); }
It is all working now.
regards.
-
5. Re: Async e-mail on registration
lobotomy Feb 10, 2013 6:35 PM (in response to kapitanpetko)So if in asynch method there is no conversation context we can not really utilize lazy loading, because than renderer wont be able to access any lazy loaded objects since there is no extended entity manager, in rendered page we can only access objects that are passed as params.
am I correct?