i have problem with <p:fileDownload>
when i try to download file and bean throws exception page reloaded and removes parametr from url:
<p:commandLink update=":gform:growl" ajax="false"
onclick="PrimeFaces.monitorDownload(null, stop)">
<i class="fa fa-paperclip fa-2x sc-badge-icon sc-border-right hover"></i>
<p:fileDownload value="#{taskFileController.getFile(cc.attrs.scFile)}"/>
</p:commandLink>
bean code:
public void getFile(ScFile scFile) throws IOException {
try {
File file = ftpController.downLoadFile(scFile);
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
response.setHeader("Content-Disposition", "attachment;filename=\"" + scFile.getFileName() + "\"");
response.setContentLength((int) file.length());
input = new FileInputStream(file);
byte[] buffer = new byte[1024];
out = response.getOutputStream();
while (input.read(buffer) != -1) {
out.write(buffer);
out.flush();
}
FacesContext.getCurrentInstance().getResponseComplete();
} catch (GrowlException e) {
GrowlException.show(e);
} catch (Throwable err) {
err.printStackTrace();
GrowlException.show("Возникла ошибка при скачивании файла");
}
}
P.s. when no exception page do not reloaded.
P.s.s. bean is @Named
and @Stateless