I have the following code of commandLink:
<h:commandLink id="number1" immediate="true" value="Downloadfile" action="#{businessBean.downloadFileAsZip}">
And downloadFileAsZip method:
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext eContext = context.getExternalContext();
HttpServletResponse response = (HttpServletResponse) eContext.getResponse();
response.reset();
response.setContentType("application/zip");
response.setCharacterEncoding("UTF-8");
try (ServletOutputStream out = response.getOutputStream()) {
try (ZipOutputStream zOut = new ZipOutputStream(out, Charset.forName("cp866"))) {
byte[] data = ...some data....;
zOut.putNextEntry(new ZipEntry("some file"));
zOut.write(data);
zOut.closeEntry();
zOut.flush();
}
}
facesContext.responseComplete();
I guess that it is impossible to download a file and rerender the page components within the same response. Is there a possible solution so that when the button is clicked, not only the file is downloaded, but also the jsf component with a specific id is updated?