Please tring following code:
public void download() {
try {
attachment attach = attachments.get(attachmentRowId);
byte[] binaryData = attach.getFile();
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("fileName", "FILE_NAME");
response.setContentType(contentType);
response.setContentLength(binaryData.length);
response.setHeader("Content- Disposition", "attachment; filename= \"" + attach.getFileName() + "." + attach.getFileType() + "\"");
ServletOutputStream out = response.getOutputStream();
out.write(binaryData);
out.flush();
out.close();
response.flushBuffer();
FacesContext.getCurrentInstance().responseComplete();
}
catch (Exception e) {
e.printStackTrace();
}
}