-
1. Re: I think we need a s:resourceLink tag
cjalmeida Jun 13, 2008 9:00 PM (in response to dhinojosa)I vouche for such tag. The code I use looks like a very nasty hack.
FacesContext facesContext = FacesContext.getCurrentInstance(); HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); response.setContentType("application/octet-stream"); response.setHeader("Content-disposition", "attachment; filename='myfile.txt'"); OutputStream out = response.getOutputStream(); out.write(data); out.close(); facesContext.responseComplete();
IMO, you should also especify an optional
filename
attribute. If it's set, the component should ignore mimeType and returnapplication/octet-stream
. According to HTTP specification, the user agent should present thesave as
dialog instead of trying th o show the file. -
2. Re: I think we need a s:resourceLink tag
dan.j.allen Jun 14, 2008 3:59 AM (in response to dhinojosa)Take a look at chapter 13 again of Seam in Action (13.2.5 Serving dynamic documents). There is an example of how to do this it a fairly elegant way using Seam's DocumentStore component. Granted, it probably would be nice to implement a component that did all of this work automatically, so I think the idea is good, but you can definitely get some mileage out of what Seam has today.
Here's a quick copy-paste taking out of context:
byte[] binaryData = ...; DocumentData data = new DocumentData("report" new DocumentData.DocumentType("pdf", "application/pdf"), binaryData); String docId = documentStore.newId(); documentStore.saveData(docId, data); String documentUrl = documentStore.preferredUrlForContent( data.getBasename(), data.getDocumentType().getExtension(), docId); redirect(documentUrl);