pe:documentViewer in dialog is caching?

Community Driven Extensions Project
Post Reply
rider
Posts: 497
Joined: 05 Mar 2010, 13:17

08 Aug 2020, 13:21

Hi all,

I´m currently try to create a PDF (which already working).
I´m creating the PDF from a URL.
So if I change something in the content from this URL and open the p:dialog again, also my PDF should be refreshed....

But it seems the content in the dialog is not updated. The pdf generation function is called, but it seems it´s still caching on client side?
Did I forgot something?

Function to call the PDF creation:

Code: Select all

<h:form id="myForm">
						<p:commandButton value="Show Preview" 
									update=":previewDialogForm" ajax="true" resetValues="true"
									actionListener="#{generatePdfDocumentDesignerController.createPDF()}"
									oncomplete="PF('previewWidgetDlg').show();">
									<p:resetInput target=":previewDialogForm" />
								</p:commandButton>
</h:form>
Dialog:

Code: Select all

	<h:form id="previewDialogForm">
		<p:dialog id="previewDialog" widgetVar="previewWidgetDlg"
			appendTo="@(body)" header="Vorschau" showHeader="true"
			maximizable="true" contentWidth="80%" contentHeight="80%"
			height="85vh" width="85vw" minimizable="false" dynamic="true"
			modal="true" resizable="false" closable="true" closeOnEscape="true">


			<pe:documentViewer id="generatedPdf"
				style="height: 83vh; width: 82vw" zoom="100" cache="false"
				value="#{generatePdfDocumentDesignerController.pdfFile}" />


			<f:facet name="footer">
				<div class="EmptyBox2"></div>
				<div class="Fright">
					<p:commandButton id="cancelBtn" value="Abbrechen"
						styleClass="RaisedButton" style="margin-right: 15px;"
						icon="fa fa-window-close" onclick="PF('previewWidgetDlg').hide()"
						type="button" />


				</div>
				<div class="EmptyBox2"></div>
			</f:facet>
		</p:dialog>
	</h:form>
Bean:

Code: Select all

@Named
@ApplicationScoped
public class GeneratePdfDocumentDesignerController implements Serializable {

...

	public void createPDF() {

		FacesContext facesContext = FacesContext.getCurrentInstance();

		try {

			String url = createUrl();
			pdfFile = null;

			PipedOutputStream os = new PipedOutputStream();
			PipedInputStream is = new PipedInputStream(os);

			managedExecutorService.submit(() -> {

				try {
					PdfRendererBuilder builder = new PdfRendererBuilder();
					XRLog.setLevel(XRLog.CSS_PARSE, Level.SEVERE);

					builder.withUri(new URL(url).toString());
					builder.toStream(os);

					builder.run();
					os.close();

				} catch (IOException e) {
					LOGGER.error(ExceptionUtils.getFullStackTrace(e));
				}
			});
			
			pdfFile = new DefaultStreamedContent(is, "application/pdf");

		}

		catch (Exception e) {
			ErrorMessage.showErrorMessage();
		}

		facesContext.responseComplete();

		LOGGER.info("END createPDF");
	}
Any ideas?
Primefaces 12.0, WildFly 21

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

08 Aug 2020, 14:36

Have you debugged that generatePdfDocumentDesignerController.createPDF() is actually generating a new PDF?

Can you create a small reproducible example using https://github.com/primefaces/primefaces-test so I can debug?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

rider
Posts: 497
Joined: 05 Mar 2010, 13:17

08 Aug 2020, 18:11

Yes, it´s called the function if I press a second one the button to open the dialog...

Is there something missing in my p:commandButton to remove the content from the current p:dialog which was open before?
It seems for me stil it´s caching, because also the second time when I open the dialog is open much more quicker then the first time...
Primefaces 12.0, WildFly 21

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

09 Aug 2020, 13:59

No your update="" is telling the dialog to replace itself correctly. The only other thing you can try is to set your dialog to dynamic="true"
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

rider
Posts: 497
Joined: 05 Mar 2010, 13:17

09 Aug 2020, 15:03

I have already dynamic="true" in my p:dialog (please see above code). Or what do you mean?
Primefaces 12.0, WildFly 21

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

09 Aug 2020, 15:36

Ahh i didn't notice that. Dynamic="True" should do an AJAX call to get the contents of the dialog and your update="" should update.

Once again if you want me to debug it please provide a small reproducer using: https://github.com/primefaces/primefaces-test
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

rider
Posts: 497
Joined: 05 Mar 2010, 13:17

17 Aug 2020, 17:35

OMG! :shock:
I´ve debugged now also and it was the case also for outputText etc.

I had in my bean this code:

FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.responseComplete();

I removed that and it was working.
Sorry for this confusion.
Primefaces 12.0, WildFly 21

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

17 Aug 2020, 18:06

no problem. gad you got it solved.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests