[jboss-user] [JBoss Seam] - Re: Usage for downloading uploaded file
carloszaniolo
do-not-reply at jboss.com
Tue Jul 17 15:09:54 EDT 2007
Hi,
try this:
<s:link value="Donwload #{textm.name}" rendered="#{! empty textm.text}" action="#{textmcontroller.download}" />
public void download() {
| if (textm.getText() != null) {
| byte[] file = loadFile();
| String name = getName();
| String type = getContentType();
| MyUtil.download(file, name, type);
| }
| }
public static void download(byte[] file, String name, String type) {
| FacesContext facesContext = (FacesContext) Component.getInstance("facesContext");
| if (!facesContext.getResponseComplete()) {
| HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
| response.setContentType(type);
| response.setContentLength(file.length);
| response.setHeader("Content-disposition","attachment; filename=" + name);
| ServletOutputStream out;
| try {
| out = response.getOutputStream();
| out.write(file);
| out.flush();
| } catch (IOException e) {
| //TODO: something
| }
| facesContext.responseComplete();
| }
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4065117#4065117
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4065117
More information about the jboss-user
mailing list