-
1. Re: Excel attachment in email
ztiringer Feb 5, 2009 3:53 PM (in response to ztiringer)Is there any version of Seam in which mail with Facelets attachments works?
-
2. Re: Excel attachment in email
nickarls Feb 6, 2009 7:56 AM (in response to ztiringer)Hmm, can't remember when I last tried. Look for the mail and pdf examples and see if you can get it working with a PDF attachment - the Excel attachment is a copy&paste solution of that.
-
3. Re: Excel attachment in email
ztiringer Feb 6, 2009 6:37 PM (in response to ztiringer)Hi Nicklas,
Yes, the mail example works for me, actually that's what I used as a template...
I even tried today to send as an attachment a PDF with various EL expressions that I display in my application, and it worked, too.
Could it be that some Excel tags are not supported? Though I don't think so, because it should be generated when FaceletsRenderer.run is called, the same as when I just do the plain file download, and it works there...
-
4. Re: Excel attachment in email
jeckhart Mar 27, 2009 9:15 PM (in response to ztiringer)Hi Niklas, Zoltan,
I think the problem lies in the mail attachment code actually. The code has a special case to handle pdf files in order to force the JSF to render and prevent the normal redirect (which instructs the browser to download the file).
In src/mail/org/jboss/seam/mail/ui/UIAttachment.java
... @Override public void encodeBegin(FacesContext context) throws IOException { if (this.getChildCount() > 0) { if (Reflections.isInstanceOf(this.getChildren().get(0).getClass(), "org.jboss.seam.pdf.ui.UIDocument")) { Method method = Reflections.getSetterMethod(this.getChildren().get(0).getClass(), "sendRedirect"); Reflections.invokeAndWrap(method, this.getChildren().get(0), false); JSF.renderChildren(context, this); } else { setValue(encode(context).getBytes()); if (getContentType() == null) { // User hasn't specified content, assume html setContentType("text/html"); } } } } ...
when I change this to:
... @Override public void encodeBegin(FacesContext context) throws IOException { if (this.getChildCount() > 0) { if (Reflections.isInstanceOf(this.getChildren().get(0).getClass(), "org.jboss.seam.pdf.ui.UIDocument")) { Method method = Reflections.getSetterMethod(this.getChildren().get(0).getClass(), "sendRedirect"); Reflections.invokeAndWrap(method, this.getChildren().get(0), false); JSF.renderChildren(context, this); } else if (Reflections.isInstanceOf(this.getChildren().get(0).getClass(), "org.jboss.seam.excel.ui.UIWorkbook")) { Method method = Reflections.getSetterMethod(this.getChildren().get(0).getClass(), "sendRedirect"); Reflections.invokeAndWrap(method, this.getChildren().get(0), false); JSF.renderChildren(context, this); } else { setValue(encode(context).getBytes()); if (getContentType() == null) { // User hasn't specified content, assume html setContentType("text/html"); } } } } ...
then the email sends properly and the attachment is correct (I've tested this on 2.1.0 GA.
Looking at the code, however, I get the sense that this is sub-optimal. It appears that you would only be able to attach either one pdf OR one spreadsheet, plus, the funny handling of the redirect seems better suited for a clause in the JSF than special handling in the code. This will also require an update if we would like to attach another new type rendered in JSF in the future (maybe a graph or an odf doc??).
I'll open an issue in JIRA (with patch) for the immediate problem as I have tested it a bit, but I'ld like to see some discussion about the other concern and how it could be fixed correctly.