Question on Mail Attachment
bsgcic May 30, 2010 9:33 PMI followed the directions in Samuel Mendenhall's article How To Upload and Download Files in Seam and got file upload and download to work. However, I cannot seem to actually attach the uploaded file to an m:message object. I do not appear to receive any errors either. The email is sent but without the attachment. I can display the #{attachment.contentTypeStr} #{attachment.nameStr} #{attachment.sizeInt} and even the #{attachment.dataBytAry} one which looks like the following: [B@1e11ff8
I would greatly appreciate any suggestions.
plain.xhtml
... <m:message xmlns:m="http://jboss.com/products/seam/mail" charset="UTF-8" importance="normal" precedence="normal"> <m:from ... /><m:replyTo .../><m:to ...><m:subject>...</m:subject> <m:attachment value="#{attachment.dataBytAry}" contentType="#{attachment.contentTypeStr}" fileName="#{attachment.nameStr}"/> <m:body type="plain">...</m:body> </m:message>
contact.xhtml
<h:form id="contactFormSubmissionForm" enctype="multipart/form-data"> <fieldset> ... <s:fileUpload id="file" data="#{attachment.dataBytAry}" contentType="#{attachment.contentTypeStr}" fileName="#{attachment.nameStr}" fileSize="#{attachment.sizeInt}"/> ...
Attachment.java
private Long id; private String nameStr; private int sizeInt; private String contentTypeStr; private byte[] dataBytAry; ... @Lob @Column(name="dataInt", length = 2147483647) @Basic(fetch = FetchType.LAZY) public byte[] getDataBytAry() { return dataBytAry; } public void setDataBytAry(byte[] dataBytAry)... ...
ContactFormSubmissionAction.java
@Stateful @Name("contactFormSubmission") @Scope(EVENT) @TransactionAttribute(REQUIRES_NEW) public class ContactFormSubmissionAction implements ContactFormSubmission ... @PersistenceContext private EntityManager entityManager; @In(create=true) private MailEngine mailEngine; @In(create=true) private Attachment attachment; ... public void register() { ... entityManager.persist(attachment); ... mailEngine.sendPlain(); }
MailEngine.java
... public void sendPlain() { ... renderer.render("/mail/plain.xhtml"); ...
Thank you
Jeff