[prev in list] [next in list] [prev in thread] [next in thread]
List: myfaces-user
Subject: RE: Re: [Tobago] Problem with PDF download and Ajax
From: "H. Swaczinna" <swaczinna () wlp-systems ! de>
Date: 2007-02-27 21:29:15
Message-ID: 19371214.452231172611755017.JavaMail.servlet () kundenserver
[Download RAW message or body]
<head></head><body>Hi Madan,<br><br>here's a (stripped) example I use to generate \
print files within java code:<br><br> <tc:button \
id="printButton" <br> \
label="Print"<br> \
immediate="true"<br> \
transition="false"<br> \
action="#{mainController.printAction}"/><br><br> public void printAction() \
{<br> String pathname = \
System.getProperty("java.io.tmpdir");<br> String filename = \
"test.pdf";<br> File pdfFile = new File(pathname, \
filename);<br> try {<br> PrintStream \
out = new PrintStream(pdfFile);<br> // Write the PDF \
content<br> \
out.println(...);<br> \
out.close();<br> sendFile(pathname, filename, \
"application/pdf");<br> } catch (IOException x) \
{<br> LOG.error("Can't create PDF file", \
x);<br> }<br> }<br><br>Regards<br>Helmut<br><br><br><table \
width="100%"><tbody><tr><td bgcolor="blue" width="5"> </td><td><style \
type="text/css"></style><div><div>Hi Helmut,<br><br>As per ur code, u give the \
location of a PDF doc on the server.<br><br>Which when referred then that would be \
downloaded.<br><br>But what if a pdf doc is generated within a javacode, say with \
Jasper Reports.<br><br>How can i pass that pdf doc generated in runtime to the jsp \
page and display that ?<br><br>Thnx in \
Advance,<br><br>Regards,<br>Madan<br> <br><br><div>----- Original Message \
----<br>From: Bernd Bohmann <bernd.bohmann@atanion.com><br>To: MyFaces \
Discussion <users@myfaces.apache.org><br>Sent: Tuesday, 27 February, 2007 \
4:25:31 AM<br>Subject: Re: [Tobago] Problem with PDF download and \
Ajax<br><br><div>Hello Helmut,<br><br>just solved see:<br><br><a \
href="http://issues.apache.org/jira/browse/TOBAGO-303">http://issues.apache.org/jira/browse/TOBAGO-303</a><br><br>Should \
be available with the next nightly build<br><br>Regards<br><br><br>Bernd<br><br>H. \
Swaczinna wrote:<br>> Hi,<br>> <br>> I've a page with a link to download a \
PDF file. The PDF download itself<br>> works without a problem. But after a \
download Ajax requests don't work<br>> anymore, for example a popup or a tabGroup \
with reloadTab.<br>> <br>> Here's a small testcase for this behavior.<br>> \
<br>> The page:<br>> <br>> <%@ taglib uri="<a \
href="http://myfaces.apache.org/tobago/component%22">http://myfaces.apache.org/tobago/component"</a>; \
prefix="tc" <br>> %><%@ taglib uri="<a \
href="http://java.sun.com/jsf/core%22">http://java.sun.com/jsf/core"</a>; prefix="f" \
<br>> %><%@ page contentType="text/html;charset=UTF-8" language="java" \
<br>> %><%@ page pageEncoding="UTF-8" <br>> \
%><f:view<br>> ><tc:page id="testPage" width="300px" \
height="200px"><br>> \
<tc:panel><br>> <f:facet \
name="layout"><br>> \
<tc:gridLayout cellspacing="0" \
<br>> \
rows="fixed;fixed"/><br>> \
</f:facet><br>> <tc:link \
id="pdfLink"<br>> \
label="PDF"<br>> \
immediate="true"<br>> \
transition="false"<br>> \
actionListener="#{anlagenController.showPDFActionListener}"><br>> \
<f:attribute name="file" \
value="test1.pdf"/><br>> \
</tc:link><br>> <tc:link \
id="ajaxLink"<br>> \
label="Ajax"><br>> \
<tc:attribute name="renderedPartially" \
value="testPopup"/><br>> \
<f:facet name="popup"><br>> \
<tc:popup id="testPopup" width="300" \
height="200"><br>> \
<tc:button id="closeButton" \
<br>>
label="Close"><br>> \
<tc:attribute name="popupClose" \
value="immediate"/><br>> \
</tc:button><br>> \
</tc:popup><br>> \
</f:facet><br>> \
</tc:link><br>> \
</tc:panel><br>> </tc:page><br>> \
</f:view><br>> <br>> The java code for the PDF download:<br>> \
<br>> public void showPDFActionListener(ActionEvent e) \
{<br>> String filename = \
(String)e.getComponent().getAttributes().get("file");<br>> \
sendFile(attachmentPath, filename, "application/pdf");<br>> }<br>> \
<br>> protected void sendFile(String filepath, String filename, \
String mimeType) {<br>> File file = new File(filepath, \
filename);<br>> if (file.exists() && \
file.isFile()) {<br>> try \
{<br>> InputStream in = new \
FileInputStream(file);<br>> \
FacesContext facesContext = \
FacesContext.getCurrentInstance();<br>> \
HttpServletResponse response = \
<br>> \
(HttpServletResponse)facesContext.getExternalContext().getResponse();<br>> \
response.setContentType(mimeType);<br>> \
response.setContentLength(in.available());<br>>
response.setHeader("Content-disposition", \
<br>> " \
attachment;filename=\"" + filename + \
"\"");<br>> ServletOutputStream \
out = response.getOutputStream();<br>> \
byte[] buffer = new byte[0x10000];<br>> \
while (in.read(buffer) > 0) \
{<br>> \
out.write(buffer);<br>> \
}<br>> \
in.close();<br>> \
out.close(); <br>> \
StateManager stateManager = \
(StateManager)facesContext.getApplication().getStateManager();<br>>
stateManager.saveSerializedView(facesContext); \
<br>> \
facesContext.responseComplete();<br>> } catch \
(Exception x) {<br>> \
getLog().error("Error writing output", \
x);<br>> }<br>> } \
else {<br>> getLog().error("File " + \
file.getAbsolutePath() + " not found");<br>> \
}<br>> }<br>> <br>> I think there's a problem with \
Ajax when a page submit has no result.<br>> <br>> Regards<br>> \
Helmut<br>> <br></div></div><br></div></div><br>
<hr size="1">
Here's a new way to find what you're looking for - <a \
href="http://us.rd.yahoo.com/mail/in/yanswers/*http://in.answers.yahoo.com/">Yahoo! \
Answers</a> </td></tr></tbody></table></body>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic