A fix for Seam mail
[Logo]
Forums for ICEfaces and ICEpdf
[Search] Search   [Recent Topics] Recent Topics   [Groups] Home Page | www.icefaces.org  [Register] Register  [Login] Login 
A fix for Seam mail  XML
Forum Index -> JBoss Seam Integration Go to Page: Previous  1, 2, 3 Next 
Author Message
gstacey

Joined: 11/07/2007 00:00:00
Messages: 18
Offline


Hmmm...

How are you calling the emailSend method? Can you post the relevant code? Also, what is the extra mapping for?
Code:
   	<servlet-mapping>
   		<servlet-name>Persistent Faces Servlet</servlet-name>
   		<url-pattern>/inc/mail_developerAndValidator.xhtml</url-pattern>
   	</servlet-mapping>
 
Newlukai

Joined: 29/11/2006 00:00:00
Messages: 125
Offline


Hi,

this extra mapping was for test purposes since I got an exception which told me that the Persistent Faces Servlet was needed. This mapping is already removed ;)

I have a page which shows a list of entries and each of this entry refers to a specific user of the system. Now you can use checkboxes to select entries and a button to send an email to the selected users. So I have a button:

Code:
<h:commandButton action="#{statistics.sendMails}" image="img/icon_buttonLine_sendMails.gif" styleClass="graphical" />


which calls this method:

Code:
@Stateful
 @Scope(ScopeType.SESSION)
 @Name("statistics")
 public class StatisticsAction implements Statistics, Serializable {
   private static final long serialVersionUID = -2193510578285970349L;
 
   @PersistenceContext(unitName = "aresDatabase")
   private transient EntityManager em;
   
   @In
   private User user;
   
   @In
   private AsynchronousIceFacesMailProcessor asynchronousMailProcessor; 
   
   public void sendMails() {
 //    String template = "/inc/mail_developerAndValidator.xhtml";
     String template = "/inc/mail_simple.xhtml";
     
     List<StatisticsForUser> statistics = getStatisticsToMail();
     for(int i = 0; i < statistics.size(); i++) {
       HashMap<String, Object> contextMap = new HashMap<String, Object>();
       contextMap.put("user", user); 
       contextMap.put("statisticForUser", statistics.get(i));
 
       asynchronousMailProcessor.scheduleEmailSend(2000 + i*500, template, contextMap); 
     }
   }


I don't see any differrences to your version, so I don't have any idea why I can't use h:outputText. If you need more code (I reduced it to the - in my eyes - relevant part) just tell me.

Thanks in advance
Newlukai
Newlukai

Joined: 29/11/2006 00:00:00
Messages: 125
Offline


I just had a debug session. Using ICEfaces, the renderers for <h:> tags are replaced by renderers provided by ICEfaces. Those renderers make use of DOMResponseWriter which expects a BridgeFacesContext as parameter. This parameter is somewhere in the call stack taken from FacesContext.getCurrentInstance(). But since the UIMessage calls MailFacesContextImpl.start() which replaces FacesContext's instance by itself and makes your MockBridgeFacesContext to a member, the cast to (BridgeFacesContext) can't be done in DOMResponseWriter.

I see only two possibilities: don't use h tags when using icefaces.jar, or use just-ice.jar. Since I have to change too much if I want to use just-ice.jar, I prefer the first possibility. Do you have another idea?
judy.guglielmin

Joined: 20/02/2007 00:00:00
Messages: 1043
Offline


When you use just-ice.jar, the whole point is not to use the ICEfaces renderers with the h tags and to this delegate to the jsf renderers. In this way you can distinguish between the 2 handlers.
Newlukai

Joined: 29/11/2006 00:00:00
Messages: 125
Offline


Sorry, I don't know if I got it right. Could you please explain it a little more detailed?

Is there any drawback using just-ice.jar?
judy.guglielmin

Joined: 20/02/2007 00:00:00
Messages: 1043
Offline


Check the sample application attached to http://jira.icefaces.org/browse/ICE-2321

Newlukai

Joined: 29/11/2006 00:00:00
Messages: 125
Offline


But to run this I need Seam 2.1.0?
judy.guglielmin

Joined: 20/02/2007 00:00:00
Messages: 1043
Offline


Yeah....Pete did some work with 2.1.0 for this to work, but you might want to try with the latest 2.0.3 release (CR1??) as he may have put it in both. Originally the portal support was only in 2.1.0, but it also made it to the 2.0.2 release. I don't have time right now to try it myself, but it might be worth a shot. Let me know.

Otherwise, you have to use gstacey's fix.
Newlukai

Joined: 29/11/2006 00:00:00
Messages: 125
Offline


ATM I'm testing my app with just-ice.jar and it seems that most of it still works. Some few features don't work anymore ...
Anyway, I used gstaceys fix which works as expected but I had to transfer the "h:outputText render=" stuff to the bean. It now decides which one out of three templates has to be sent. It would be perfect if it worked as it should. Sometimes the mail isn't sent without any information and sometimes I get an exception on the frontend after a mail was sent. I don't know why ...
gstacey

Joined: 11/07/2007 00:00:00
Messages: 18
Offline


Newlukai wrote:
I just had a debug session. Using ICEfaces, the renderers for <h:> tags are replaced by renderers provided by ICEfaces. Those renderers make use of DOMResponseWriter which expects a BridgeFacesContext as parameter. This parameter is somewhere in the call stack taken from FacesContext.getCurrentInstance(). But since the UIMessage calls MailFacesContextImpl.start() which replaces FacesContext's instance by itself and makes your MockBridgeFacesContext to a member, the cast to (BridgeFacesContext) can't be done in DOMResponseWriter.

 


I'm puzzled why you get this error. The issue you describe is exactly what this workaround is working around. Are you sure that the you have the latest code? have you debugged into the workaround code? In the context.wrap at the start of the emailSend method it sets the responseWriter to an HtmlResponseWriter. If you step through it with the debugger, is this happening? It can't be or you would not see the error you describe...
Newlukai

Joined: 29/11/2006 00:00:00
Messages: 125
Offline


I'm using the version of your code which can be found in JIRA. The only differences are the package statement and the catch clause in scheduleEmailSend.

Perhaps I've to use a newer Seam version? I'm using 2.0.1.

As far as I can see, your wrap and unwrap methods do what they should. The problem is that deeper in the lifecycle you context is wrapped by a Seam context which can't be cast to BridgeFacesContext. I don't know how your code could prevent this wrapping.

And I have another problem. From time to time it happens that scheduleMailSend finishes successfully, but the mail is never sent. Do you have any idea how this can happen? Probably it's this call is problematic:

Code:
public void sendMails() {
     List<StatisticsForUser> statistics = getStatisticsToMail();
     
     for(int i = 0; i < statistics.size(); i++) {
       StatisticsForUser sfu = statistics.get(i);
       HashMap<String, Object> contextMap = new HashMap<String, Object>();
       contextMap.put("user", user); 
       contextMap.put("statisticForUser", sfu);
       contextMap.put("releaseDescr", selectedRelease.getDescr());
       
       String template = "/inc/mail_developerAndValidator.xhtml";
       if(sfu.isSendDeveloperMail() && !sfu.isSendValidatorMail()) {
         template = "/inc/mail_developer.xhtml";
       } else if(!sfu.isSendDeveloperMail() && sfu.isSendValidatorMail()) {
         template = "/inc/mail_validator.xhtml";
       }
 
       try {
         asynchronousMailProcessor.scheduleEmailSend(2000 + i*500, template, contextMap);
       } catch(Exception e) {
         FacesUtil.addMessage("", "error_stats_mailSend", "error_stats_mailSend_queuing",
           statistics.get(i).getUser().getName());
       }
       
       FacesUtil.addMessage(null, null, FacesMessage.SEVERITY_INFO, "info_stats_mailSend",
         "info_stats_mailSend_pending", statistics.get(i).getUser().getName());
     }
   }
gstacey

Joined: 11/07/2007 00:00:00
Messages: 18
Offline


The key thing in the wrap method is that it resets the responseWriter from a DOMResponseWriter, which would try to do the cast you are mentioning, to a basic HTMLResponseWriter which does not do this cast.

As for the email not sending, I would check whatever email logs you have available to see if it got sent. Most such errors in my testing came from the email getting stuck in someones spam filter. Perhaps look at using Meldware to handle the delivery.
dammi

Joined: 06/02/2008 00:00:00
Messages: 16
Offline


Can somebody help me with what I need to change in the
http://jira.icefaces.org/secure/attachment/11035/AsynchronousIceFacesMailProcessor.java
in order to get it to work with Seam 2.0.2.SP1?

Maybe somebody who has already got a working solution could just post the file.

thanks
gstacey

Joined: 11/07/2007 00:00:00
Messages: 18
Offline


It's working fine in 2.0.2SP1 for me, as posted. What error are you getting?
dammi

Joined: 06/02/2008 00:00:00
Messages: 16
Offline


The imports

Code:
 import org.jboss.seam.ui.util.JSF;
 import com.sun.faces.RIConstants;
 import com.sun.faces.application.ViewHandlerImpl;
 import com.sun.faces.renderkit.html_basic.HtmlResponseWriter;
 


cannot be resolved.

There is a org.jboss.seam.util.JSF instead of the org.jboss.seam.ui.util.JSF, but this class hasn't got the method renderChildren which is used in line 112

Code:
 JSF.renderChildren(facesContext, root);
 
 
Forum Index -> JBoss Seam Integration Go to Page: Previous  1, 2, 3 Next 
Go to:   
Powered by JForum 2.1.7ice © JForum Team