He is right this is not necessarily a Turbine specific question, but we have done what 
you are looking for.

Tony O.


Here is another solution if you want to do more than just display a static page within 
the IFrame.  We have a web page with standard html controls as the page header and an 
adobe pdf viewer embedded within the Iframe.  We have also displayed other various 
child web pages within the IFrame.

Embed the IFrame within a table cell (on the parent form) using, (note the NAME and 
SRC attributes are important).

<IFRAME NAME="frame0"
              SRC="about:blank"
              width=860
              height=565
              marginwidth=0
              marginheight=0
              frameborder=0
              style="background:#EEEEEE none;"
              SCROLLING="auto">
      </IFRAME>


Include a <body> tag on the parent form as follows...    <body onload="loadIFrame();">

Once the parent form is loaded it will fire off the following javascript method. (The 
javascript needs to be including in the parent form)

The javascript will write the contents of the concatenated html string variable 
directly to the IFrame.  This will cause the contents of the html string to initially 
load and display within the IFrame.  Note that this html contains its own 
onload="doneWithDummyFormSetup();" statement.  Once the IFrame is initially loaded 
this event causes it to submit another Turbine request to populate the IFrame with 
whatever you want.


<SCRIPT>

  function loadIFrame() {

    var html = '';

    ## add an event that can be fired off when the intial contents of the
    ## iframe have completed loading with the dummy form, this will force the iframe 
to submit
    ## a second request (which will be for the actual PDF)
    ##
    ## this is really just a way to get the desired event to fire off at the correct 
time
    ## once the main form has initially appeard on the screen
    ##
    ## note that this function is within the scope of the iframe itself

    html += ' <SCRIPT> ';
    html += '   function doneWithDummyFormSetup() { ';
    html += '       window.top.loadActualPDF(); ';
    html += '   } ';
    html += ' <\/SCRIPT> ';


    ## initially load the iframe with a dummy form so that we can get a handle to 
something within
    ## the iframe (that allows request submittals), so that we can submit a second 
request (through
    ## the iframe itself) for the actual PDF

    html += ' <link rel="stylesheet" type="text/css" href="screen.css" title="Screen 
Styles" media="screen"> ';

    html += ' <body onload="doneWithDummyFormSetup();"> ';

    html += ' <form name="displayForm" id="displayForm" method="post" 
action="$link.setPage("DisplaySingleWorkOrder.vm").setAction("DisplaySingleWorkOrderAction")">
 ';

    html += ' <table width="860" border="0" cellpadding="0" cellspacing="0" 
summary=""> ';

    html += '   <tr> ';
    html += '     <td width="100%">&nbsp;<\/td> ';
    html += '   <\/tr> ';

    html += '   <tr> ';
    html += '     <td width="100%">&nbsp;<\/td> ';
    html += '   <\/tr> ';

    html += '   <tr> ';
    html += '     <td align="center" width="100%"><b>Please Wait Loading Work 
Order...<\/b><\/td> ';
    html += '   <\/tr> ';

    html += ' <\/table>';

    html += ' <\/form> ';

    html += ' <\/body> ';

    frame0.document.open();
    frame0.document.write(html);
    frame0.document.close();

  }


  function loadActualPDF() {

    /* this function does a submit through the iframe in order to load it */
    /* with the pdf for the current workorder_id */

    ## get a reference to frame0 and force it to submit its own request

    ## get a valid reference to the form within the iframe
    var displayFormObject = frame0.document.forms["displayForm"];
    if (displayFormObject != null) {

      ## check to see if the form has already been submitted by checking for a 
      ## dummy form element
      var mySubmit = displayFormObject.elements["zzz_form_submit"];
      if (mySubmit == null) {

        ## add a dummy form element so that we can test for re-dundant form 
submissions 
        var oInput=frame0.document.createElement("input");
        oInput.type = "hidden";
        oInput.name = "zzz_form_submit";
        oInput.id = "zzz_form_submit";
        oInput.value = "1";
        displayFormObject.appendChild(oInput);

        var oEvent=frame0.document.createElement("input");
        oEvent.type = "hidden";
        oEvent.name = "eventSubmit_doDisplay";
        oEvent.id = "eventSubmit_doDisplay";
        oEvent.value = "Something";
        displayFormObject.appendChild(oEvent);

        ## submit a Display request so that the iframe form
        ## loads the pdf
        displayFormObject.submit();

      }

    }

  }

</SCRIPT>


If you are curious how to display the PDF here is the Turbine action class event code. 
 We are pre-generating and storing the PDF's within a database BLOB field, but you 
should be able to read in any document and send it.

   public void doDisplay (RunData data, Context context) throws Exception {

        // pull up the PDF from here and display it, since we do not want
        // to be pushing any of the pdf data into the session

        SearchDataHandler searchData = (SearchDataHandler) getFormHandler(data, 
context);

        Row searchRow = searchData.getRow();
        if (searchRow == null) {
            return;
        }

        String workOrderId = searchRow.getColumn("workorder_id");

        if (workOrderId.equals("0") == false) {

            RowCollection pdfRc = new RowCollection();
            RowCollectionSQLLoaderSaver ls = new 
RowCollectionSQLLoaderSaver(RowCollectionSQLLoaderSaver.ORACLE);

            String query = "SELECT pdf_image FROM jpa_job_workorder_pdf WHERE 
workorder_id = " + workOrderId;

            ConnectionHandler ch = new ConnectionHandler();
            Connection conn = ch.getConnection(dbInstance);
            ls.appendCollection(pdfRc, query.toString(), conn);
            ch.releaseConnection();

            Row row = pdfRc.getRow(1);

            if (row != null) {

                byte[] pdf = (byte[]) row.getColumnObject("pdf_image");

                ServletOutputStream outputStream = 
data.getResponse().getOutputStream();
                HttpServletResponse response = data.getResponse();

                //response.setHeader("Content-disposition-type", "attachment");

                // either one of the following approaches works correctly
                // response.setHeader("Content-type", "application/pdf");
                response.setContentType("application/pdf");

                response.setHeader("Content-disposition", "filename=WorkOrder" + 
workOrderId + ".pdf");
                response.setIntHeader("Content-length", pdf.length);

                outputStream.write(pdf, 0, pdf.length);
                outputStream.flush();

            }

        }

    }

Reply via email to