• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to hide primefaces blockui after pdf generation

 
Raghu Sundar
Ranch Hand
Posts: 40
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am generating pdf and displaying it in separate window/tab using the approach described in BalusC Code: PDF handling.I need to display blockui ajax loader when i select the commandlink to display pdf.The pdf gets generated but the ajax loader image remains as it is.I need to manually refresh the page to hide it.Is there any way using which it can be hidden as soon as the pdf gets displayed.

My code snippet is as below

JSF page

snippet of Managed bean which is of request scope
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really do not recommend using JSF to generate non-HTML output. It's awkward, error-prone, and complicated. It's much simpler to let a basic servlet or JSP generate things like PDF's, Excel/Word documents and general XML files.

I'm not 100% certain I understood what it is that you are actually attempting to do, since you couched it in terms of an expected specific technical solution instead of in terms of what you want the user to experience, but I'm going to assume that you want a JSF page to display a PDF in a separate tab/window(*) and replace that PDF in its tab/window when you change some parameters and click the "display" button again on the original JSF control page. That's a common function.

The simplest way to do that in JSF is to write a stand-alone servlet to generate the PDF or use some sort of template engine for that purpose. That gets around all of the hack code that attempting to use JSF itself to render the PDF requires.

To make this mechanism work, you simply use a JSF outputLink tag with the "target" attribute to invoke this stand-alone servlet/template engine. The JSF form can update the report parameters as backing bean properties in session scope and the PDF renderer can then use this same session-scope object to obtain them for rendering purposes. If you use a fixed name (not one of the "magic" built-in HTML target names) for the target attribute, any previous contents of the window/pane given that target name will be replaced when the reporting servlet/engine returns its response.

* Note that due to legal requirements, Internet Explorer is forbidden to embed plugin output into IE windows and it will thus be forced to actually launch a separate display app.
 
Raghu Sundar
Ranch Hand
Posts: 40
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,Thanks for your reply.My actual requirement is that i have a webpage in my app built with JSF 2 and primefaces.It has a selectone menu and a commandlink to do an action by selecting appropriate option.One of the option is to preview pdf by selecting a record from the datatable.It is actually report generated at the background using record details and should be previewed in browser.I have implemented blockui for all the options and they are working good(The status indicator starts and stops with start and completion of action) except for previewing where the status indicator remains intact with pdf generated in separate window/tab.I need to manually refresh the page in order to hide the blockui indicator.The reason may be that the preview request is of non-ajax type and oncomplete action is not working on the component.

Can you please suggest me if there is any way using which the indicator can be hidden as soon the pdf gets previewed.
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I'm just going to have to throw out some random answers in the hope that it helps. I can't figure out what the PrimeFaces "blockUI" tag is actually good for, although it does seem to be pretty plain that it's designed for AJAX use and not full-page replacement operations.

One thing that almost never works well in JSF is Request Scope. That is due to how JSF does postbacks. Almost always you need View or Session scope on a backing bean.

And, as I mentioned previously, I don't recommend using JSF to render PDF, in any event. There's no practical benefit to it and quite a bit of downside.

A "preview" in the browser is only possible under Internet Explorer if the preview is an image, not an embeddable document such as a PDF, because Microsoft got sued for half a billion dollars by a company that holds patents on that sort of thing and Microsoft lost. So they had to remove that capability from IE.

Somewhat related to that is that you cannot embed a PDF within an HTML page even on browsers that didn't have that restriction (such as Chrome, Safari and Firefox), because PDF and HTML require distinctly different client-side renderers and few, if any of the popular browsers support a PDF embedded object even when the legal forbidding doesn't apply. So the controlling JSF page and the PDF would definitely have to be separate windows, generated by separate HTTP requests. The technique I described earlier can handle that, whether you're doing a full document or just a preview sample document.


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!