2013-10-20 2 views
0

현재 보고서 프로젝트에서 jsf2, primefaces 4 및 omnifaces를 사용하고 있습니다. 파라미터에 기초pdf 또는 html 응답으로 동적으로 jsf 페이지 업데이트

<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> 

가 reportBean.generate 방법 PDF 응답 또는 다음과 같이 reportBean로부터 HTML 응답 하나를 생성 할 것이다 :

는 I는 다음과 JSF 형태를 갖는다.

> 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,... 

어떻게 출력 패널에 응답을 표시합니까?

+0

pdf가 생성되는 HTML 응답 또는 html은 무엇입니까? – BholaVishwakarma

+0

http://www.primefaces.org/showcase/ui/media.jsf – kolossus

답변

0

코드에 따르면 먼저 바이트 배열 스트림을 PDF로 변환하고 두 번째 서블릿을 만들어야합니다.

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

또는 코드 : 당신은 응답 PDF를 설정할 수 있습니다

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

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> 

를 내가 생각하는 서블릿을 만들지 않으려면 가능하면 outputLink의 value에 파일 경로를 추가하십시오. 그것을 시도하십시오!