6 Replies Latest reply on May 13, 2009 7:43 PM by Nicklas Karlsson

    exportKey in PDF?

    Robert Morse Apprentice

      Any plans of adding an exportKey attribute to p:document as is available in the excel piece?

        • 1. Re: exportKey in PDF?
          Nicklas Karlsson Master

          Now that you mentioned it I had some discussions with Norman in October or so but then the mailthread probably got buried under other stuff. Yes, I came to think it when reading the DB-PDF thread.


          It would probably be useful. There is a sendRedirect attribute on document but it's currently only used for controlling if the data goes the normal way of end up in a ValueHolder. And the data is only placed in the DocumentStore when you go the redirect-route so there is no way(?) of hijacking the DocumentStore and pull the data back out instead of redirecting so the exportKey would probably be handy.


          Here is your chance to contribute, clear it with Norman and send him a patch for UIDocument and the documentation and I'm sure he'll stick it in ;-) It's probably a 90% copy&paste from the Excel version.

          • 2. Re: exportKey in PDF?
            Robert Morse Apprentice

            Will do.  Thanks.

            • 3. Re: exportKey in PDF?
              Stefano Travelli Newbie

              I like this idea.


              I'm looking forward to get rid of this hack:


                  public static void renderToDataStream(String viewId, OutputStream out) throws IOException
                  {
              
                      EmptyFacesContext emptyFacesContext = new EmptyFacesContext();
              
                      try
                      {
                          Renderer.instance().render(viewId);
                      } finally
                      {
                          emptyFacesContext.restore();
                      }
              
                      GetinDocumentStore docStore = GetinDocumentStore.instance();
              
                      Map<String, DocumentData> dataStore = docStore.getDataStore();
              
              
                      for (DocumentData data : dataStore.values())
                      {
                          data.writeDataToStream(out);
                      }
                      dataStore.clear();
                  }
              
              public class EmptyFacesContext extends MockFacesContext
              {
                  FacesContext originalFacesContext;
              
                  public EmptyFacesContext()
                  {
                      super(new MockExternalContext());
                      originalFacesContext = FacesContext.getCurrentInstance();
                      createViewRoot();
                      FacesContext.setCurrentInstance(this);
                  }
              
                  public void restore()
                  {
                      setCurrentInstance(originalFacesContext);
                  }
              
              }
              
              
              


              • 4. Re: exportKey in PDF?
                Robert Morse Apprentice

                I already had the 2.1.2.CR1 source, so I made the change as you suggested, and it works just fine.  I updated a feature request JIRA, and I'll wait for a reply from Norman before checking out the latest source and submitting a patch.  Thanks again for all of your help!

                • 5. Re: exportKey in PDF?
                  Norman Richards Expert

                  Is this really the way you guys think this should work?  I've always been of opinion that if we did this it there should be an action called to render a template that could be saved somewhere as opposed to having that be the side effect of some other view being rendered. 


                  But, you guys are the ones with the need here, and if this mechanism solves your problem best, I've got no problem going that route.

                  • 6. Re: exportKey in PDF?
                    Nicklas Karlsson Master

                    Other solutions are of course always welcome, this was just meant as a workaround with minimal impact to solve a specific need.


                    For Seam 3 there could be a document module or such where we have a set of general utils for dealing with this. If we target Servlet 3.0 at some point, there could even be a self-registering servlet for dealing with downloads(?)