1 Reply Latest reply on Apr 24, 2008 3:22 PM by gus888

    IceFaces and Seam mail

    gstacey

      Hi all,


      Like more than a few others I have been wanting to use Seam mail alongside IceFaces for a while now, but it doesn't work. There is a workaround now apparently by using just-ice.jar but I created my own fix before I came across this. Anyway, I thought I'd share my fix.


      What I have done is take the AsynchronousMailProcessor class from the mail example from the Seam examples and added a workaround for the IceFaces compatibility issue.


      The workaround involves messing with the FacesContext and its viewroot (it resets them when the email is done) so unfortunately it can't access your Seam contexts directly. I get around this by passing the emailer a hashmap of context items I want in the new context.


      To send an email is pretty simple. First inject the mailProcessor component then call scheduleEmailSend.


      e.g. from the forgotPassword handler in my current project
      @In
      private AsynchronousIceFacesMailProcessor asynchronousMailProcessor;
      ...


      private void sendForgotEmail()
      {
      String template = /templates/emails/forgotpassword.xhtml;
      User user = getUser();


      HashMap<String, Object> contextMap = new HashMap<String, Object>();
      contextMap.put(user, user);
      contextMap.put(password, user.resetPassword());


      // schedule the email to be sent 5000ms from now
      asynchronousMailProcessor.scheduleEmailSend(5000, template, contextMap);


      }



      I don't see any way to upload a file here so I'll direct people to my post on the IceFaces forum to get the code.
      http://www.icefaces.org/JForum/posts/list/8058.page#33826


      Feel free to use this however you like. It's been working well for me for a while now but I only abstracted it to the point that it was divorced my my clients code (allowing me to share it) today. I won't offer any support for it but if you have issues you can certainly send me an email and I'll take a look when I can. If anyone wants to modify / improve upon it also feel free, just let me know so I can reap the benefits too.