I want to view a pdf file that is stored as a blob
in my Oracle Database. I'm using a <p:media/>
in the xhml
, and StreamedContent
in the backing bean.
Here is xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<p:outputPanel id="outputPanelDialogShowPdf">
<div style="text-align: center">
<p:media value="#{bean.media}" width="600px" height="300px" player="pdf" />
</div>
<p:spacer height="1px" />
<div style="text-align: center">
<p:commandButton value="#{msgs.button_cancel}" icon="ui-icon-cancel" oncomplete="dialogShowPdf.hide();"
action="#{bean[cancelAction]}" immediate="true" />
</div>
</p:outputPanel>
And here is the action button (which is part of data table) which calls the action bean
<p:commandButton value="Show PDF"
update=":formMediaDataDialogShowPdf:outputPanelDialogShowPdf"
oncomplete="PF('dialogShowPdf').show()"
action="#{ bean.showPdfAction }" rendered="#{ mediaData.mediaType == 'application/pdf'}">
<f:setPropertyActionListener value="#{mediaData}" target="#{bean.selectedMediaData}" />
</p:commandButton>
And this is the action in the bean
public void showPdfAction(){
if (null != selectedMediaData) {
media = new DefaultStreamedContent(new ByteArrayInputStream(selectedMediaData.getMediaData()),"application/pdf");
}
}
The problem is that the media is not being displayed even though the action in the bean runs without errors, and the media
property in the bean is being properly initialized.
Can anyone provide some help for that