0 Replies Latest reply on Jul 2, 2010 4:38 AM by scoobymib3.scoobymib3.aol.com

    Renderer and the documents id within the DocumentStore

    scoobymib3.scoobymib3.aol.com

      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