Put this action in some Seam component.
<s:link action="{someSeamComponent.download}"
value="Download"/>
And the action in SomeSeamComponent
| public void download() {
| //Here you get the entity that has a byte array with the data
| SomeEntity entity = getEntityFromEntityManager();
|
|
| FacesContext facesContext = FacesContext.getCurrentInstance();
| HttpServletResponse response = (HttpServletResponse) facesContext
| .getExternalContext().getResponse();
| response.setContentType(entity.getContentType());
| //Asume a data property inside entity
| byte[] data = entity.getData();
| response.setContentLength(data.length);
| response.setHeader("Content-disposition", "inline;
filename=\""
| + entity.getFileName() + "\"");
|
| try {
|
| OutputStream out = response.getOutputStream();
|
| out.write(data);
|
| out.flush();
| out.close();
|
| facesContext.responseComplete();
| } catch (IOException ex) {
| FacesMessages.instance().add(
| "Error while downloading the file: " + entity.getFileName());
| }
|
| }
|
|
Cheers
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4084868#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...