3 Replies Latest reply on May 24, 2011 3:51 AM by René Zoller

    Pageflow and PDF documentStore

    Tony Kay Newbie

      Short Question: What do I put in a pageflow to allow a faclet PDF to be rendered as part of the navigation?


      Details:


      I have a pageflow in which one of the steps needs to allow the user to print a PDF version of a contract. The PDF is generated via a facelet (and thus goes through the documentStore and a redirect). I have a control page that is within the pageflow:


      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
           xmlns:s="http://jboss.com/products/seam/taglib"
           xmlns:ui="http://java.sun.com/jsf/facelets"
           xmlns:f="http://java.sun.com/jsf/core"
           xmlns:h="http://java.sun.com/jsf/html"
           xmlns:a="http://richfaces.org/a4j"
           xmlns:rich="http://richfaces.org/rich"
           template="/layout/template.xhtml">
      
           <ui:define name="body">
                <h:form id="client" styleClass="edit">
                     <rich:panel>
                     <!-- FIXME: add nav rule for pageflow to PDF GEN -->
                          <s:link id="print" view="/consignmentContract.xhtml"  
                               value="Printable Contract" /><br/>
                          <s:button id="done"     value="Done" action="done"/>
                     </rich:panel>
                </h:form>
           </ui:define>
      
      </ui:composition>
      



      and the consignmentContract.xhtml is the PDF facelet. I need the conversation to be preserved, because the PDF uses elements from the conversation. When I click on the Printable Contract link, it tries to do the rendering, but then returns me to the control page with an illegal navigation message.


      Obviously, the pageflow is denying the navigation redirect to the PDF. So, is there anything I can put in there to tell the pageflow that the PDF transition is OK? Or, do I have to do something screwy like end the pageflow without ending the converation?

        • 1. Re: Pageflow and PDF documentStore
          Tony Kay Newbie

          I got a bit further on this. I added the following to my pageflow:


          <page name="contract" view-id="/consignmentContractControls.xhtml" back="enabled" redirect="true">
               <transition name="done" to="gather info"></transition>
               <transition name="print" to="contractPDF"></transition>
          </page>
               
          <page name="contractPDF" view-id="/consignmentContract.xhtml" back="enabled" redirect="false">
               <transition to="contract"></transition>
          </page>
          



          which lets me get to the PDF generated by consignmentContract.xhtml. I tried adding a default transition (as shown) that should take me back to the control page in the state diagram, but it doesn't work. Any action I try to take on the controls page just re-sends the PDF...so it is obviously stuck on the contractPDF page. (My browser is Firefox without a helper, so the PDF comes as a download, and the controls page stays on the screen).


          The controls page looks like this now:


          <h:form id="client" styleClass="edit">
               <rich:panel>
                    <s:link action="print" id="print" value="Printable Contract" /><br/>
                    <s:link action="done" id="done"     value="Return to Previous Screen" />
               </rich:panel>
          </h:form>
          



          If I enable the back button feature (as shown), the user can at least use that to get back to the previous page.


          Any ideas on how I can force the pageflow back to the contract state?


          I'm going to try EL within the facelet that generates the PDF...I'll post how that goes.

          • 2. Re: Pageflow and PDF documentStore
            Tony Kay Newbie

            OK, I figured out at least one way of doing it that seems to work well.



            • Add the .xhtml file that generates the PDF as a legal page in the pageflow. Have at least one transition go to that node (which will send the PDF). If you don't do this, then the navigation enforcement of the pageflow won't let the PDF be served. The documentstore does some funky redirects, so any transitions in this node seem to be ignored. Therefore, you don't need any exit transitions in the PDF node (though I guess they don't hurt, if you want them for documentation):



            <page name="contract" view-id="/consignmentContractControls.xhtml" redirect="true">
                 <transition name="done" to="gather info"></transition>
                 <transition name="print" to="contractPDF"></transition>
            </page>
                 
            <page name="contractPDF" view-id="/consignmentContract.xhtml" redirect="false">
            </page>
            




            • Add a method that returns an empty (but not null) string to one of your conversation beans that can force the token back to the contract node using the pageflow component:



            @In("org.jboss.seam.pageflow.pageflow")
            Pageflow pageflow;
            
            public String getControlsHack() {
               log.info("Repositioning pageflow token to contract");
               pageflow.reposition("contract");
               return "";
            }
            




            • Use the controlsHack property anywhere in the markup of your PDF. I tried putting the control hack just about everywhere in the JPDL as an action expression, but with no luck. The PDF rendering happens after the JPDL processing, and therefore resets the token properly.



            <p:paragraph>#{bean.controlsHack}...</p:paragraph>
            



            That seemed to do it for me. The only catch I can see is if you use the cached instance in the document store somehow (so that the PDF is not regenerated, but the token moves to the PDF node in the JPDL).


            Other suggestions are welcome.

            • 3. Re: Pageflow and PDF documentStore
              René Zoller Newbie
              Thank you Tony,

              this worked fine for me! Only one point to add from my point of view. One has to configure the pdf-feature properly, discribed here: http://docs.jboss.org/seam/2.2.2.Final/reference/en-US/html/itext.html#itext.configuration