Download Excel file from Seam component...
yshashidhar Aug 10, 2010 11:56 PMHi
I have a requirement where in I need to give functionality to user for downloading excel file from server.
I was walking through various posts over here, but my issue is not resolved... Please see below what I have done..
xhtml code:
<s:link id="slinkexportxls" value="Download" action="#{qualityIP.exportExcel}">
</s:link>
And here is my exportExcel method:
createExcel();
HttpServletResponse httpResponse =
(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
System.out.println("injected extCtx, httpoutput buffersize= - " + httpResponse.getBufferSize());
File fFile = new File("D:\\Shashi\\ExportInspectionPlanToExcel.xls");
String stFileName = "ExportInspectionPlanToExcel.xls";
httpResponse.setHeader ("Content-Disposition","attachment;filename=\""+stFileName+"\"");
//the content type set as excel
httpResponse.setContentType("application/vnd.ms-excel");
System.out.println("ExportInspectionPlanToExcel: Set all return properties...");
//Open an input stream to the file and post the file contents thru the
//servlet output stream to the client m/c
InputStream isStream = null;
ServletOutputStream sosStream = null;
try {
//response.flushBuffer();
isStream = new FileInputStream(fFile);
sosStream = httpResponse.getOutputStream();
int ibit = 256;
while ((ibit) >= 0){
ibit = isStream.read();
sosStream.write(ibit);
}
System.out.println("ExportInspectionPlanToExcel: Done, closing all open streams...");
sosStream.flush();
System.out.println("Flushed, closing sos...");
sosStream.close();
} catch (IOException exp){
System.out.println("exception -" +exp.getStackTrace());
}
FacesContext.getCurrentInstance().responseComplete();
And that's it I have done... when I ran the above application... I don't see exportExcel method getting called after clicking Download
Seam link
Can any help please me where did I made mistake?