私は私の問題を解決するために次のことができることを発見しました -
私のBeanクラスでは、次のコードを書きました-
HttpServletResponse response = (HttpServletResponse) getFacesContext().getExternalContext().getResponse();
ByteArrayOutputStream outputStream = null;
try {
outputStream = //Call service to generate the extract, return outputStream ;
if(outputStream != null){
response.setContentType(T3Constants.MIME_ZIP);
response.setHeader(T3Constants.CONTENT_DISPOSITION, ATTACH_FILE_NAME);
response.getOutputStream().write(outputStream.toByteArray());
response.flushBuffer();
FacesContext.getCurrentInstance().responseComplete();
outputStream.close();
} else {
formatFacesMessage(FacesMessage.SEVERITY_WARN, "No data for selected filter", "No data for selected filter");
}
}
私のサービスでは、次のコードを書きました-
ByteArrayOutputStream outputStream = null;
if(CollectionUtils.isNotEmpty(list returned from DB)) {
outputStream = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(outputStream);
//Add files to ZIP
outputStream = new ByteArrayOutputStream();
workbook.write(outputStream);
zos.putNextEntry(new ZipEntry(xlsName.toString()));
zos.write(outputStream.toByteArray());
zos.flush();
zos.close();
return outputStream;
}
ありがとう、ラーズ