Project Documentation


Tag name: <tr:fileDownloadActionListener>

The fileDownloadActionListener tag is a declarative way to allow an action source (<commandButton>, <commandLink>, etc.) to programatically send the contents of a file to the user, optionally with a specific content type and filename.


This example sends a simple "Hello there!" file to the user.

            <h:commandButton value="Say Hello">
              <tr:fileDownloadActionListener filename="hello.txt"
                                        contentType="text/plain; charset=utf-8"
    public void sayHello(FacesContext context, OutputStream out) throws IOException
      OutputStreamWriter w = new OutputStreamWriter(out, "UTF-8");
      w.write("Hi there!");
      // The stream is automatically closed, but since we wrapped it,
      // we'd better flush our writer


Name Type Supports EL? Description
contentType Object Yes the MIME type of the file, for example text/plain, text/csv, application/pdf, etc.
filename Object Yes the proposed filename for the object. When set, a "Save File" dialog will typically be displayed, though this is ultimately up to the browser. If not set, the content will typically be displayed inline in the browser if possible.
method Object Only EL the method that will be used to download the file contents. The method takes two arguments, a FacesContext and an OutputStream. The OutputStream will be automatically closed, so the sole responsibility of this method is to write all bytes to the OutputStream.