Hi,
I have a class which renders a number of PDF's and then saves them into a database. I am having a problem, once the document is rendered, getting the appropriate document from the document store. Everything is working as it should but I am hard coding the id in as 1
so the document that it stores is never correct.
How can I dynamically get the id of the document I have just rendered?
private byte[] createBytes() { EmptyFacesContext emptyFacesContext = new EmptyFacesContext(); Context conversation = Contexts.getConversationContext(); byte[] bytes = null; try { Renderer renderer = Renderer.instance(); String id = renderer.render("/restrict/requests/templates/notice.xhtml"); DocumentStore doc = DocumentStore.instance(); if (doc != null) { DocumentData data = doc.getDocumentData("1"); DocumentData byteData = null; if (data instanceof DocumentData) { byteData = (DocumentData) data; } else { throw new IllegalArgumentException("Couldnt get the bytes from the pdf document, unknown class " + data.getClass().getName()); } bytes = byteData.getData(); } return bytes; } catch (Exception ex) { ex.printStackTrace(); return null; } finally { emptyFacesContext.restore(); } }
Thanks in advance for your help...
Cheers
Martin