Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String json() throws IOException, TransformerException, SAXException, ParserConfigurationException {
- Gson gson = new Gson();
- String result = gson.toJson(selectedEvidence);
- String xml = JSONvXML.readFile(result);
- return xml;
- }
- public void download() throws IOException, TransformerException, SAXException, ParserConfigurationException {
- String fileName = "Verzija";
- FacesContext fc = FacesContext.getCurrentInstance();
- ExternalContext ec = fc.getExternalContext();
- ec.responseReset(); // Some JSF component library or some Filter might have set some headers in the buffer beforehand. We want to get rid of them, else it may collide.
- ec.setResponseContentType("application/pdf");
- ec.setResponseHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); // Shrani z Pop-up window
- OutputStream output = ec.getResponseOutputStream();
- String xml = json();
- OutputStreamWriter osw = new OutputStreamWriter(output);
- PrintWriter writer = new PrintWriter(osw);
- writer.write(xml);
- writer.flush();
- writer.close();
- XmlVPDF v = new XmlVPDF();
- v.toPDF(xml, output);
- fc.responseComplete(); // Important! Otherwise JSF will attempt to render the response which obviously will fail since it's already written with a file and closed.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement