Email Problem
fpsdyl Jan 6, 2009 7:14 AMHi all, I am having some serious problems in sending email.. :-( not making me a happy guy - I want to just send out a test email messages to more than one recipient from the db , this is what I use:
`
@Name("emailService")
@AutoCreate
@Stateful
@Scope(ScopeType.APPLICATION)
public class EmailService implements EmailServiceLocal{
@Logger Log log;
@Remove public void remove(){}
@In(create=true)
Renderer renderer;
@In(create=true)
AuthenticatorLocal authenticator;
@Out(required=true, value="eList",scope=ScopeType.APPLICATION)
List<User_E> eList;
@Asynchronous
@Transactional
public void sendMail(){
if (eList == null || eList.size() < 1){
getMailUsers();
}
log.info("loading list into context");
Contexts.getApplicationContext().set("eList", eList);
log.info("--> outjected!");
renderer.render("/statsEmailReport.xhtml");
}
@Factory("eList")
public void getMailUsers() {
List<User_E> allUsers = authenticator.fetchAllUsers();
List<User_E> emailUsers=new ArrayList<User_E>();
for(User_E user : allUsers){
if (user.getNotifyStats() == Boolean.TRUE){
emailUsers.add(user);
}
}
log.info("size of emailUsers -:" + eList.size());
eList = emailUsers;
}
}
`
And the view I want to render is this one :
=
<ui:repeat xmlns="http://www.w3.org/1999/xhtml"
xmlns:m="http://jboss.com/products/seam/mail"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
value="#{eList}" var="user">`
<m:message>
<m:from name="dylanjaneke" address="dylanjaneke@noreply.com" />
<m:to name="#{user.fullname}" address="#{user.email}"/>
<m:subject>Seam Email</m:subject>
<m:body>
<p><h:outputText value="Dear dude" /></p>
<p>You can try out Seam by visiting<a href="http://labs.jboss.com/jbossseam">http://labs.jboss.com/jbossseam</a>.</p>
<p>Regards,</p>
<p> Dylan</p>
</m:body>
</m:message>
</ui:repeat>
=
I keep getting the following error :
`
Caused by: java.lang.NullPointerException
at util.EmailService.getMailUsers(EmailService.java:66)
at util.EmailService.sendMail(EmailService.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:
`
I don't think that "eList" is actually outjected into the context? -or atleast the correct context , I once read something about a difference between the servlet context/ mock context. But I was sure that Contexts.getApplicationContext.set(...) would work, especially because I figured the view would be rendered before the variable get's outjected using the annotation.. that's just what I think.
--> And sorry about the ugly formatting I couldn't get the view in here view backticks...
Please let me know if you have any ideas.
Thanks-
`
@Name("emailService")
@AutoCreate
@Stateful
@Scope(ScopeType.APPLICATION)
public class EmailService implements EmailServiceLocal{
@Logger Log log;
@Remove public void remove(){}
@In(create=true)
Renderer renderer;
@In(create=true)
AuthenticatorLocal authenticator;
@Out(required=true, value="eList",scope=ScopeType.APPLICATION)
List<User_E> eList;
@Asynchronous
@Transactional
public void sendMail(){
if (eList == null || eList.size() < 1){
getMailUsers();
}
log.info("loading list into context");
Contexts.getApplicationContext().set("eList", eList);
log.info("--> outjected!");
renderer.render("/statsEmailReport.xhtml");
}
@Factory("eList")
public void getMailUsers() {
List<User_E> allUsers = authenticator.fetchAllUsers();
List<User_E> emailUsers=new ArrayList<User_E>();
for(User_E user : allUsers){
if (user.getNotifyStats() == Boolean.TRUE){
emailUsers.add(user);
}
}
log.info("size of emailUsers -:" + eList.size());
eList = emailUsers;
}
}
`
And the view I want to render is this one :
=
<ui:repeat xmlns="http://www.w3.org/1999/xhtml"
xmlns:m="http://jboss.com/products/seam/mail"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
value="#{eList}" var="user">`
<m:message>
<m:from name="dylanjaneke" address="dylanjaneke@noreply.com" />
<m:to name="#{user.fullname}" address="#{user.email}"/>
<m:subject>Seam Email</m:subject>
<m:body>
<p><h:outputText value="Dear dude" /></p>
<p>You can try out Seam by visiting<a href="http://labs.jboss.com/jbossseam">http://labs.jboss.com/jbossseam</a>.</p>
<p>Regards,</p>
<p> Dylan</p>
</m:body>
</m:message>
</ui:repeat>
=
I keep getting the following error :
`
Caused by: java.lang.NullPointerException
at util.EmailService.getMailUsers(EmailService.java:66)
at util.EmailService.sendMail(EmailService.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:
`
I don't think that "eList" is actually outjected into the context? -or atleast the correct context , I once read something about a difference between the servlet context/ mock context. But I was sure that Contexts.getApplicationContext.set(...) would work, especially because I figured the view would be rendered before the variable get's outjected using the annotation.. that's just what I think.
--> And sorry about the ugly formatting I couldn't get the view in here view backticks...
Please let me know if you have any ideas.
Thanks-