Smaller sample:

*Contact.tml*
<html t:type="layout" title="Contact com.kids.crm"
      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
      xmlns:p="tapestry:parameter">

    <p>Contact com.kids.crm ...</p>
<t:form t:id="doReportsForm"  >
       <t:submit t:id="onSubmit" name="Run Report" value="Run Report" />
</t:form>
</html>



*Contact.java*
package com.kids.crm.pages;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;

import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.annotations.InjectPage;

import com.kids.crm.reports.pdf.PDFGenerator;
import com.kids.crm.reports.pdf.PDFStreamResponse;



public class Contact
{
        public StreamResponse onSubmit() {              
                 try {
                        System.out.println("\n\n\n\n\nContact\n\n\n\n");
                    File tmpFile = File.createTempFile("hava", null);
                    BufferedWriter br = new BufferedWriter(new 
FileWriter(tmpFile));
                    br.append("something to test\nAnother line to test");
                    br.flush();
                    br.close();

                    return new PDFStreamResponse(new
FileInputStream(tmpFile.getAbsolutePath()), "results_file");
                 } catch (IOException e) {
                     e.printStackTrace();
                 }

                   return null; 
                
                
    }
}

*
PDFStreamResponse.java*
package com.kids.crm.reports.pdf;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletResponse;

import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.services.Response;

public class PDFStreamResponse implements StreamResponse{
        private InputStream is;
    private String filename="default";

    public PDFStreamResponse(InputStream is, String args) {
            this.is = is;
                    this.filename = args;
    }

    public String getContentType() {
            return "application/pdf";
    }

    public InputStream getStream() throws IOException {
            return is;
    }

    public void prepareResponse(Response arg0) {
            arg0.setHeader("Content-Disposition", "attachment; filename="
                            + filename + ".pdf");
    }


}




--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/fault-found-tp5026068p5026316.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to