Descargando un archivo CSV usando JSF

No sé cómo descargar un archivo CSV. El CSV será generado en tiempo de ejecución. ¿Debo guardar primero el archivo en el directorio WEB-INF de Tomcat? Estoy usando JSF 1.2.

Por cierto, ¿cuál es el componente JSF favorito para este tipo de tarea?

Editar (05.05.2012 - 15:53)

Probé la soluciónBalusC declarado en su primeraenlazar, pero si hago clic en el botón de comando, el contenido del archivo se muestra en la página web. Tal vez hay un problema con elmimetype?

archivo xhtml:

<code><a4j:form>
    <a4j:commandButton action="#{surveyEvaluationBean.doDataExport}" value="#{msg.srvExportButton}" />
</a4j:form>
</code>

frijol principal

<code>    public String doDataExport() {

    try {
        export.downloadFile();  
    } catch (SurveyException e) {
        hasErrors = true;
    }
    return "";
}
</code>

haba de exportación

<code>public void downloadFile() throws SurveyException {

    try {

        String filename = "analysis.csv";

        FacesContext fc = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();

        response.reset();
        response.setContentType("text/comma-separated-values");
        response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");

        OutputStream output = response.getOutputStream();

        // writing just sample data
        List<String> strings = new ArrayList<String>();

        strings.add("filename" + ";" + "description" + "\n");
        strings.add(filename + ";" + "this is just a test" + "\n");

        for (String s : strings) {
            output.write(s.getBytes());
        }

        output.flush();
        output.close();

        fc.responseComplete();

    } catch (IOException e) {
        throw new SurveyException("an error occurred");
    }
}
</code>

Editar (05.05.2012 - 16:27)

Resolví mi problema. Tengo que usar<h:commandButton> en lugar de<a4j:commandButton> y ahora funciona!

Respuestas a la pregunta(2)

Su respuesta a la pregunta