Baixando um arquivo CSV usando o JSF

Eu não sei como baixar um arquivo CSV. O CSV será gerado em tempo de execução. Preciso salvar o arquivo no diretório tomcat WEB-INF primeiro? Estou usando o JSF 1.2.

By the way, qual é o componente JSF favorecido para este tipo de tarefa?

Editar (05.05.2012 - 15:53)

Eu tentei a soluçãoBalusC afirmou em sua primeiraligação, mas se eu clicar no meu commandButton o conteúdo do arquivo é exibido na página da web. Talvez haja um problema com omimetype?

arquivo xhtml:

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

feijão principal:

<code>    public String doDataExport() {

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

export-bean:

<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)

Eu resolvi meu problema. Eu tenho que usar<h:commandButton> ao invés de<a4j:commandButton> e agora funciona!

questionAnswers(2)

yourAnswerToTheQuestion