美好的一天,我在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();
}