Hm, looks quite similar to how I offer excel files for download.
You can adding "facesContext.responseComplete();" at the end of
your down1()-method.
Hi,
i wanna wrete some input in a csv-file for the user to dowload.
the code:
private void down1() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse res = (HttpServletResponse) context
.getExternalContext().getResponse();
// Set the headers.
res.setContentType("application/x-download");
String fileName = "file.csv";
res.setHeader("Content-Disposition", "attachment;filename=\""
+ fileName + "\"");
String separator = ",";
String linebreak = System.getProperty("line.separator");
Writer wr;
wr = res.getWriter();
// CSV-Header
String headerRowString = "labela,labelb,labelc";
wr.write(headerRowString);
String rowString = "";
for (int i = 1; i < 10; i++) {
rowString = "valuea" + i + separator + "valueb" + i +
separator
+ "valuec" + i;
wr.write(linebreak);
wr.write(rowString);
}
wr.close();
}
the result:
<html><head><title></title></head><body>labela,labelb,labelc
valuea1,valueb1,valuec1 valuea2,valueb2,valuec2 valuea3,valueb3,valuec3
valuea4,valueb4,valuec4 valuea5,valueb5,valuec5 valuea6,valueb6,valuec6
valuea7,valueb7,valuec7 valuea8,valueb8,valuec8
valuea9,valueb9,valuec9</body></html>
But i need a csv-file. In a other project (no jsf) it works fine.
Please help.
Thanks.
bye
uwe
--
View this message in context:
http://www.nabble.com/File-download-CSV-makes-a-html-file-tf4605133.html#a131495
49
Sent from the MyFaces - Users mailing list archive at Nabble.com.