0

Currently i am using jsf2, primefaces 4 and omnifaces in my report project.

I have jsf form with as follows:

    <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:p="http://primefaces.org/ui"
            xmlns:pe="http://primefaces.org/ui/extensions"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:f="http://java.sun.com/jsf/core" >
    <ui:composition template="/templates/reportLayout.xhtml">
         <ui:define name="centerContent">

        <h:form>
        Parameter 1: <p:inputText />
        Parameter 2: <p:inputText />

        Output Type: 
            <p:selectOneMenu>
                <f:selectItem itemValue="html" />
                <f:selectItem itemValue="pdf" />
            </p:selectOneMenu>
        <hr/>
        <p:commandButton value="Generate Report" 
            action="#{reportBean.generate}" />
        </h:form>

        <p:outputPanel id="output">
                <p:lightBox iframe="true">

                </p:lightBox>
        </p:outputPanel>
         </ui:define>
    </ui:composition>
    </html>

Based on the parameters, reportBean.generate method will generate either pdf response or html response from the reportBean as follows.

> res27: String = application/pdf

> res28: Array[Byte] = Array(37, 80, 68, 70, 45, 49, 46, 54, 13, 10, 57, 32, 48, 3
  2, 111, 98, 106, 13, 10, 60, 60, 47, 84, 121, 112, 101, 47, 88, 79, 98, 106, 1
  01, 99, 116, 47, 83, 117, 98, 116, 121, 112, 101, 47, 70, 111, 114, 109, 47, 7
  , 119, 51, -30,...

How do i display the response in the output panel ?

1 Answers1

0

According by your code first you need convert byte array stream to PDF and second create one servlet. You can set pdf to response:

response.setHeader("Content-Disposition", "inline;filename=file.pdf");

Or this code:

response.setHeader("Content-Disposition", "attachment;filename=file.pdf");

and call it in p:lightBox:

<p:lightBox iframe="true" width="80%" height="80%" >

    <h:outputLink value="#{facesContext.externalContext.requestContextPath}/YourServlet" title="Here is Pdf"> 
        <h:graphicImage library="common\images" name="pdf.png" />
    </h:outputLink> 
 </p:lightBox>  

If don't want to create servlet I think it is possible add file path to value of outputLink. Please try it!

herry
  • 1,708
  • 3
  • 17
  • 30