在JSF中下载文件后面向消息

时间:2014-06-02 09:41:49

标签: java javascript jsf

美好的一天,我在Java中下载了在JSF中调用的文件函数。

但是在下载文件后,页面中没有显示FacesMessage ..

背后有什么理由吗?

我在xhtml中有一个代码:

<h:commandButton id="submit" value="#{message.btn_submit}" action="#{bean.doProcess}"/>
在Backing bean中

public void doProcess() {
MessageUtil.addMessage("SOME MESSAGE");
FacesContext faces = FacesContext.getCurrentInstance();
                       HttpServletResponse response = (HttpServletResponse) faces.getExternalContext().getResponse();
                       response.setContentType("application/pdf");
                       response.setContentLength(pdf.length);

                       List<String> ids= request.getIds();
                       String fname = utilsFactory.getPDFFilename(hwbs);

                       StringBuilder sb = new StringBuilder("attachment; filename=\"")
                        .append(fname)
                        .append("\"");
                       String removeNewLine = sb.toString().replaceAll("\\r|\\n", "");

                    response.setHeader("Content-disposition", removeNewLine);
                       try {
                           ServletOutputStream out;
                           out = response.getOutputStream();
                           out.write(pdf);
                       } catch (IOException e) {
                           LOGGER.error("Unable to print to outputstream", e);
                       }
                       faces.responseComplete();
}

0 个答案:

没有答案