Mittwoch, 26. März 2014

Avoid double download of PDF in popup + inlineframe

After some research i realized that my inlineFrame which renders a pdf in a popup downloads the file twice. The first time after the popup opens and the second time after close. (hint: the popup has content delivery "lazyUncached")

I tried different ways to close the popup:

  • The dialog shows closeIcon which closes the popup
  • A button next to the inlineFrame with partialSubmit resets the url and closes the popup
  • Autoclose enabled
But it was not possible to avoid the second request on close event. I also tried to set the url of the inlineFrame to null before i close the popup with a button - i don't know how but the same request as before was fired again.

Finally i had to avoid the whole popup to have a good result.
Instead of using a real popup i created a BTF based on pages with one page in it:

<f:view>
    <af:document id="d1"
                 title="Online Postfach Mitteilung">
      <af:form id="f1">
        <af:panelStretchLayout id="psl1" bottomHeight="40px">
          <f:facet name="center">
            <af:inlineFrame id="if1" sizing="preferred"
                    source="#{myBean.URL}"/>
          </f:facet>
        </af:panelStretchLayout>
      </af:form>
    </af:document>
  </f:view>


I embed this BTF as TF-Call in my BTF of the application and set the option to run as dialog:


After that i only needed a button to trigger my TF control flow case "showPdf" in combination with UseWindow=true.


Finally i had the exact same result but my close "X" from dialog avoids the second download of the pdf via the servlet in my inlineFrame.


Every kind of close (i use the X here) simply closes the popup dialog and its BTF completely - no second request after all. :-)

2 Kommentare:

  1. The real problem here is that some browsers (specifically firefox I think) re-load the contents of the iframe when the DOM element is re-parented. When you show and hide a af:popup then exactly this happens so you can get this double loading. So it is possible to address this by deferring the setting of the source attribute on the inlineFrame using a poll. So initially you show the popup with the inlineFrame having an empty source (or pointing to a local HTML file) and then you reset and PPR to load the real doc.

    AntwortenLöschen
  2. Thanks Sir. solution worked for me

    AntwortenLöschen