Hi,
I did this with PDF a while a go as a test and then "almost" implemeted the CSV version, this should work (not sure wrote this a while ago):

    public String exportToCsv(){
        ByteArrayOutputStream outStream = new ByteArrayOutputStream ();
 
        // Write CSV data tot he outStream

 
        FacesContext faces = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) faces.getExternalContext().getResponse();
        response.setContentType("text/csv");
        response.setContentLength( outStream.size() );
        response.setHeader("Content-disposition", "attachment; filename=\"sumtab.csv\ "");
        response.setHeader("Cache-Control", "cache, must-revalidate");
        response.setHeader("Pragma", "public");

        try {
            ServletOutputStream output = response.getOutputStream();
            output.write(outStream.toByteArray() );
        } catch (IOException e) {
            log.debug("IOException in exportToCsv: " + e.toString());
        }

        faces.responseComplete();
        try {
            outStream.close();
        }
        catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

On 14/08/06, Eurig Jones <[EMAIL PROTECTED]> wrote:
I have a link on a facelets page which I want to users to be able to
click and download a text file (with it's own extension such as .csv).
The contents of this text file is simply the contents of a String
property in a jsf bean.

I'm not sure how to go about doing the above, I'm not even sure if it's
possible using JSF. Any ideas?

Regards,
Eurig

--

Fugro Robertson Limited      Telephone: +44+ (0)1492 581811
Tyn-y-coed Site              Fax: +44+ (0)1492 583416
Llanrhos
Llandudno
North Wales
UK   LL30 1SA

General Email: [EMAIL PROTECTED]

World Wide Website: www.fugro-robertson.com

********************************************************************
* This email may contain  confidential and  privileged information *
* intended solely for the individual or organisation to whom it is *
* addressed. If the reader is not the  intended  addressee, or the *
* employee  or agent responsible  to deliver  it to the addressee, *
* you are hereby notified that any  dissemination, distribution or *
* copying is strictly prohibited.  If you have received this email *
* in error, please notify the  sender and either destroy the email *
* or return it to [EMAIL PROTECTED]                          *
* Please note this email is not intended to create legal relations.*
********************************************************************


Reply via email to