No, this is really simple as an action method.

Why make it any harder than this?

   public void exportFileAction(String contentType, byte[] data,
String filename) throws IOException
   {
       FacesContext facesContext = FacesContext.getCurrentInstance();

       OutputStream responseStream =
((HttpServletResponse)facesContext.getExternalContext().getResponse()).getOutputStream();
       if (null == responseStream)  throw new
AbortProcessingException("responseStream is null");

       HttpServletResponse response =
(HttpServletResponse)facesContext.getExternalContext().getResponse();
       response.setContentType(contentType);
       response.setHeader("Content-Disposition","attachment;filename=\""
+ filename + "\"");
       response.setContentLength(data.length);
       responseStream.write(data);

       response.flushBuffer();

       facesContext.responseComplete();
   }

   public String exportFileWhenClicked()
   {
        try {
                        exportFileAction("text/plain", bean.getStringData().getBytes(), 
"file.csv");
                } catch (IOException e) {
           FacesContext.getCurrentInstance().addMessage(null,
                   new FacesMessage(FacesMessage.SEVERITY_ERROR,
                        "Write Error.", e.getLocalizedMessage()));
           return null;
                }
                
                return "export file";
   }


On 8/14/06, Eurig Jones <[EMAIL PROTECTED]> wrote:
I've now decided to go with a simple servlet because I think it's a
cleaner method to do it.

Thanks a lot for everyones help!

Ondřej Světlík wrote:
> Eurig Jones napsal(a):
>> 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
>>
>
> Hello,
>
> I have tried custom PhaseListener and Servlet. After many problems
> with the PhaseListener I had to use the Servlet solution. If you are
> still interested in PhaseListener solution, look at:
>
> 
http://www.jroller.com/page/cagataycivici?entry=phaselistener_renders_an_image_no
>
>
> Regards,
>
> Ondrej

--

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