2 Replies Latest reply on Mar 9, 2010 9:04 PM by Kurt Bliefernich

    open a browser tab by using navigation rule

    Thiagu Mariappan Novice

      hi every one


      it it possible open a new tab or new browser window by using the pages.xml navigation rule.
      this is my requirement:
      when ever a user click a link or button i need to open the PDF report in a new tab or new browser window. after open the report i need to disable the link or button to restrict the user wont open the report next time.
      if i use the h:commandLink with target value as blank it open the PDF report in the new tab , but it wont refresh the parent or main page .
      so button disable wont happened. if i try with a4j:commandLink with target and reRender open it wont open the new tab.
      i tried with s:link and target parameter also , it is open the new window but it wont refresh the main page.
      any idea how to do this one.


      thiagu.m

        • 1. Re: open a browser tab by using navigation rule
          Arbi Sookazian Master

          Good question.  Well I tried some clicking around in the itext Seam example and I noticed that none of the links open the PDF in a new tab or window.  Also, when I right-click and select open in a new tab in FF3, the PDF opens in a new tab but the focus does not change from the original tab.


          As far as opening a new tab from pages.xml, I've never heard of that but that would be cool...


          Anyways, check this out: http://docs.jboss.org/seam/2.2.0.GA/reference/en-US/html_single/#itext.document


          Note that there is no attribute for newTab or newWindow.  Most likely we need to file a JIRA enhancement request for this unless somebody knows of a good solution...

          • 2. Re: open a browser tab by using navigation rule
            Kurt Bliefernich Newbie

            I had to do something similar, but had to make a call to a cgi and return that PDF to a new tab/window (I couldn't convince my boss to just use itext in seam.)


            What I ended up doing was having a s:div with a render tag that was backed by a boolean value on the backer bean.



            <s:div rendered="#{backingBean.makeReport} >
            
            </s:div>
            



            Then inside the s:div tag I put a little javascript and a form to post to the document I needed to create.  I used jQuery to submit the form.


            <s:div rendered="#{backingBean.makeReport} id="makeForm">
              <script type="text/javascript" >
                 jQuery(document).ready(function(){
                   jQuery('#form').submit(function(){     
                      var new_window = "new_window";
                      window.open('',new_window,'');
                      this.target = new_window;
                      return true;
                   });
                   jQuery('#form').submit();
                 });
              </script>
              <form action="/report.seam" id="form" method="post">
              </form>
            </s:div>
            



            I then had a a4j:commandButton that flipped the flag to render the s:div which would submit the form and create the report.


            <a4j:commandButton type="button" 
                action="#{backingBean.renderReport}"
                value="Create Report"
                onclick="disableButton(this);" 
                reRender="makeForm"
            />
            
            <s:div rendered="#{backingBean.makeReport} id="makeForm">
              <script type="text/javascript" >
                 jQuery(document).ready(function(){
                   jQuery('#form').submit(function(){     
                      var new_window = "new_window";
                      window.open('',new_window,'');
                      this.target = new_window;
                      return true;
                   });
                   jQuery('#form').submit();
                 });
              </script>
              <form action="/report.seam" id="form" method="post">
              </form>
            </s:div>
            



            The backing bean is something like this


            private Boolean makeReport = false;
            ...
            public void renderReport(){
                setMakeReport(true);
            }
            
            public void setMakeReport(Boolean makeReport) {
                this.makeReport = makeReport;
            }
            
            public Boolean getMakeReport(){
                return this.makeReport;
            }
            



            if you disable the button onclick it will stop people from regenerating the report.


            function disableButton(button) {
                jQuery(button).attr("disabled","disabled");     
            }
            
            



            Then in the report.page.xml file you can call the method that creates the report in the <action execute="#{ReportBean.generate}" />




            This may or may not help you, but it allowed me to put PDFs in popups.