Hallo Leute,
ich habe mal wieder ein kleines Problem.
Ich habe in meinem Projekt eine ViewScoped Bean die eine Export Funktion besitzt, dabei wird ein PDF Dokument erstellt und in einer Servlet Methode in einen Outputstream geschrieben. Das is alles kein Problem, allerdings wird nach der Download Methode nochmals auf den FacesContext zugegriffen, um eine Bestätigungsnachricht auf dem Facelet anzeigen zu lassen. Allerdings wird dies nicht mehr ausgeführt.
Die Frage is nun warum und wie kann ich das beheben.
Ich hoffe ihr könnt mir helfen.
ich habe mal wieder ein kleines Problem.
Ich habe in meinem Projekt eine ViewScoped Bean die eine Export Funktion besitzt, dabei wird ein PDF Dokument erstellt und in einer Servlet Methode in einen Outputstream geschrieben. Das is alles kein Problem, allerdings wird nach der Download Methode nochmals auf den FacesContext zugegriffen, um eine Bestätigungsnachricht auf dem Facelet anzeigen zu lassen. Allerdings wird dies nicht mehr ausgeführt.
Die Frage is nun warum und wie kann ich das beheben.
Code:
try {
downloadPDF(List);
} catch (IOException e) {
SystemLogger.logger.log(Level.FINE, e.getMessage(), e);
FacesMessageGenerator.displayUserInformation(
"export:errorMessage", e);
exportSuccessful = false;
}
FacesMessageGenerator.displayUserInformation(
"export:successful", "exportSuccessful");
}
Code:
private void downloadPDF(List<Ticket> ticketList) throws IOException {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext
.getResponse();
OutputStream output = null;
// alternativ
ByteArrayOutputStream out = new ByteArrayOutputStream();
out.write(PDFConverter.convertToPDF(List));
try {
// Init servlet response.
response.reset();
response.setHeader("Content-Type", "application/pdf");
response.setHeader("Content-Disposition", "attachment; filename=\""
+ getFileName() + "\"");
output = response.getOutputStream();
out.writeTo(output);
output.flush();
} finally {
output.close();
out.close();
}
facesContext.responseComplete();
}
Ich hoffe ihr könnt mir helfen.