Hi Madan,

here's a (stripped) example I use to generate print files within java code:

    <tc:button id="printButton"
      label="Print"
      immediate="true"
      transition="false"
      action=""/>

  public void printAction() {
    String pathname = System.getProperty("java.io.tmpdir");
    String filename = "test.pdf";
    File pdfFile = new File(pathname, filename);
    try {
      PrintStream out = new PrintStream(pdfFile);
      // Write the PDF content
      out.println(...);
      out.close();
      sendFile(pathname, filename, "application/pdf");
    } catch (IOException x) {
      LOG.error("Can't create PDF file", x);
    }
  }

Regards
Helmut


 
Hi Helmut,

As per ur code, u give the location of a PDF doc on the server.

Which when referred then that would be downloaded.

But what if a pdf doc is generated within a javacode, say with Jasper Reports.

How can i pass that pdf doc generated in runtime to the jsp page and display that ?

Thnx in Advance,

Regards,
Madan
 

----- Original Message ----
From: Bernd Bohmann <[EMAIL PROTECTED]>
To: MyFaces Discussion <[email protected]>
Sent: Tuesday, 27 February, 2007 4:25:31 AM
Subject: Re: [Tobago] Problem with PDF download and Ajax

Hello Helmut,

just solved see:

http://issues.apache.org/jira/browse/TOBAGO-303

Should be available with the next nightly build

Regards


Bernd

H. Swaczinna wrote:
> Hi,
>
> I've a page with a link to download a PDF file. The PDF download itself
> works without a problem. But after a download Ajax requests don't work
> anymore, for example a popup or a tabGroup with reloadTab.
>
> Here's a small testcase for this behavior.
>
> The page:
>
> <%@ taglib uri="http://myfaces.apache.org/tobago/component"; prefix="tc"
> %><%@ taglib uri="http://java.sun.com/jsf/core"; prefix="f"
> %><%@ page contentType="text/html;charset=UTF-8" language="java"
> %><%@ page pageEncoding="UTF-8"
> %><f:view
>  ><tc:page id="testPage" width="300px" height="200px">
>     <tc:panel>
>       <f:facet name="layout">
>         <tc:gridLayout cellspacing="0"
>           rows="fixed;fixed"/>
>       </f:facet>
>       <tc:link id="pdfLink"
>         label="PDF"
>         immediate="true"
>         transition="false"
>         actionListener="#{anlagenController.showPDFActionListener}">
>         <f:attribute name="file" value="test1.pdf"/>
>       </tc:link>
>       <tc:link id="ajaxLink"
>         label="Ajax">
>         <tc:attribute name="renderedPartially" value="testPopup"/>
>         <f:facet name="popup">
>           <tc:popup id="testPopup" width="300" height="200">
>             <tc:button id="closeButton"
>               label="Close">
>               <tc:attribute name="popupClose" value="immediate"/>
>             </tc:button>
>           </tc:popup>
>         </f:facet>
>       </tc:link>
>     </tc:panel>
>   </tc:page>
> </f:view>
>
> The java code for the PDF download:
>
>   public void showPDFActionListener(ActionEvent e) {
>     String filename = (String)e.getComponent().getAttributes().get("file");
>     sendFile(attachmentPath, filename, "application/pdf");
>   }
>
>   protected void sendFile(String filepath, String filename, String mimeType) {
>     File file = new File(filepath, filename);
>     if (file.exists() && file.isFile()) {
>       try {
>         InputStream in = new FileInputStream(file);
>         FacesContext facesContext = FacesContext.getCurrentInstance();
>         HttpServletResponse response =
>           (HttpServletResponse)facesContext.getExternalContext().getResponse();
>         response.setContentType(mimeType);
>         response.setContentLength(in.available());
>         response.setHeader("Content-disposition",
>             " attachment;filename=\"" + filename + "\"");
>         ServletOutputStream out = response.getOutputStream();
>         byte[] buffer = new byte[0x10000];
>         while (in.read(buffer) > 0) {
>           out.write(buffer);
>         }
>         in.close();
>         out.close();    
>         StateManager stateManager = (StateManager)facesContext.getApplication().getStateManager();
>         stateManager.saveSerializedView(facesContext);    
>         facesContext.responseComplete();
>       } catch (Exception x) {
>         getLog().error("Error writing output", x);
>       }
>     } else {
>       getLog().error("File " + file.getAbsolutePath() + " not found");
>     }
>   }
>  
> I think there's a problem with Ajax when a page submit has no result.
>
> Regards
> Helmut
>



Here’s a new way to find what you're looking for - Yahoo! Answers

Reply via email to