From the PrimeFaces showcase, the media component used to display PDF document
But the showcase uses a static PDF document.
In real life, we might want to display different PDF documents by different use cases,
or a runtime generated PDF document.
To achieve the above purpose, we need to use the value attribute in <p:media /> component by passing in a StreamedContent from backingBean.
1. BackingBean method that return StreamedContent.
2. display the PDF content with <p:media /> component.
Done!!
But the showcase uses a static PDF document.
In real life, we might want to display different PDF documents by different use cases,
or a runtime generated PDF document.
To achieve the above purpose, we need to use the value attribute in <p:media /> component by passing in a StreamedContent from backingBean.
1. BackingBean method that return StreamedContent.
public StreamedContent getPdfDocument() {
// logic to generate the PDF
return new DefaultStreamedContent(pdfInByteArrayInputStream, "application/pdf");
}
2. display the PDF content with <p:media /> component.
<p:media value="#{myBean.pdfDocument}" width="100%" height="500px" player="pdf" />
Done!!
i am getting this exception
ReplyDeletejava.lang.IllegalArgumentException: pdf is not a valid media player type
org.primefaces.component.media.player.MediaPlayerFactory.getPlayer(MediaPlayerFactory.java:52)
org.primefaces.component.media.MediaRenderer.resolvePlayer(MediaRenderer.java:119)
org.primefaces.component.media.MediaRenderer.encodeEnd(MediaRenderer.java:41)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:905)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:875)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:439)
com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
what version of PF you are using?
DeleteI checked the PF tag doc for 3.x, 4.x, 5.x
below are the description for player attribute
Type of the player, possible values are
"quicktime","windows","flash","real" and "pdf".
java.lang.NoClassDefFoundError: javax/el/ValueReference
ReplyDeleteat org.primefaces.el.InterceptingResolver.setValue(InterceptingResolver.java:28)
at com.sun.el.parser.AstValue.setValue(AstValue.java:167)
at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:273)
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
at org.primefaces.el.ValueExpressionAnalyzer.getExpression(ValueExpressionAnalyzer.java:49)
at org.primefaces.util.DynamicResourceBuilder.build(DynamicResourceBuilder.java:49)
at org.primefaces.component.media.MediaRenderer.getMediaSrc(MediaRenderer.java:125)
at org.primefaces.component.media.MediaRenderer.encodeEnd(MediaRenderer.java:42)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! cfa level 1 mock exam pdf with answers
ReplyDeleteEnjoyed every bit of your blog post. Really looking forward to read more. Fantastic.
ReplyDeleteshare files
I really like your post. You do a fantastic job. I am thankful for you sharing this knowledge with us. I hope that was of use to you. Additionally, I'll provide you with access to the most recent blog spacebar counter. Space Bar Test allows you to test your finger speed on the space bar. You can also calculate your maximum tapping speed.
ReplyDeleteThe creation, altering and encryption of PDF record are conceivable with various sorts of converter devices on the lookout.
ReplyDeletePDF to PNG