This is a JSF question, but yes, it is possible, by accessing the JSF ExternalContext.
I have found a way that seems to work. Not SEAM related I guess, but JSF dependent.
On a bean's method:
FacesContext context = FacesContext.getCurrentInstance(); HttpServletResponse res = (HttpServletResponse)context.getExternalContext().getResponse(); ServletOutputStream os = res.getOutputStream(); os.println("Content-type: application/vnd.ms-excel"); os.println(); // write content context.responseComplete();
HttpServletResponse res = (HttpServletResponse)context.getExternalContext().getResponse(); res.setHeader("Content-type", "application/..."); ServletOutputStream os = res.getOutputStream(); // write content on os context.responseComplete();
Gavin, thanks for you answer, I've only seen it now :-(
If you do want this to work of osx and probably some other platforms, then you will also need the following line in the code
res.setHeader("Content-disposition", "attachment; filename=aFile.xls");
You may want to store the file name and return that in the above or try to map extensions to mime types. This would depend on its usage.