JSF2 + Primefaces + PDF

时间:2016-07-13 13:17:35

标签: pdf primefaces popup response

我有一个.xhtml页面:

<f:event type="preRenderView" listener="#{suspendBean.getSuspendBeanHandler()}" />

和方法getSuspendBeanHandler();

ByteArrayOutputStream baosPDF=new ByteArrayOutputStream();
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();

ec.responseReset(); 
ec.setResponseContentType("application/pdf"); 
ec.setResponseContentLength(baosPDF.size());

ec.setResponseHeader("Content-Disposition", "inline; filename=\"" + fileName + "\"");


OutputStream output = ec.getResponseOutputStream();
.....


baosPDF.writeTo(output);

fc.responseComplete(); 

我想在新的Windows浏览器中显示PDF,很可能是一个新的弹出窗口。

0 个答案:

没有答案