concept message in category seam

appears as: messages, message, The message, messages, message, The messages
Seam in Action

This is an excerpt from Manning's book Seam in Action.

Getting technologies to work with one another is more than just having them pass messages back and forth. It’s about creating an interaction that blurs the boundary between them, making them act as a single, unified technology. Seam achieves this integration by fitting EJB 3 up against the web tier, finding a place for JPA, and scrapping the ineffectual JSF managed bean container. After reviewing how Seam tackles these challenges, you get a chance to determine which Seam stack is right for you.

When the start tag is encountered during the rendering process, a new email message object, MimeMessage, is instantiated. The tags nested within <m:message> contribute to the MimeMessage object. When the end tag is encountered, the object is passed to the JavaMail Transport object, which sends the message off to the recipients.

It’s possible to embed the <m:message> tag in any Facelets template, which would result in an email message being sent when that page is rendered. In practice, however, you typically create a stand-alone template reserved for composing an email and then call on that template from Java when the message needs to be sent. We’ll get to that in a moment.

Adding an image as an attachment is not enough for most email readers to render it automatically. Even if it’s rendered, it is grouped at the bottom of the email with all of the other attachments. It would better to have the image displayed within the body of the message. To do this, you start by setting the disposition of the attachment to inline and designating a status variable that holds information about the inline attachment:

  <m:attachment value="#{newGolfer.image}"
    contentType="#{newGolfer.imageContentType}"
    fileName="#{newGolfer.username}#{newGolfer.imageExtension}"
    disposition="inline" status="profileImageAttachment"/>

You then embed an <img> tag in the body of the message that references the inline attachment using a special URL scheme. The URL consists of the scheme cid: followed by the attachment’s content id, which is read from the status variable of the attachment:

  <p><img src="cid:#{profileImageAttachment.contentId}"/></p>

You can even use the <m:attachment> in the body of the message so that you can render images in a loop. The only requirement is that you declare the attachment before trying to access its status variable:

  <ui:repeat var="_golfer" value="#{newGolfers}">
    <m:attachment value="#{_golfer.image}"
      contentType="#{_golfer.imageContentType}"
      fileName="#{_golfer.username}#{_golfer.imageExtension}"
      rendered="#{_golfer.image ne null and _golfer ne newGolfer}"
      disposition="inline" status="profileImageAttachment"/>
    <p><img src="cid:#{profileImageAttachment.contentId}"/></p>
  </ui:repeat>

If all of this inline disposition stuff seems like too much trouble, or you are concerned it will make the size of the email message too large, you have the option of serving images (and other assets such as style sheets) as linked resources just like in a web page. Let’s say you want to include the logo for Open 18 in the message. First, add it somewhere in the body: