2014-12-29 5 views
0

링크를 클릭하면 데이터베이스에서 가져온 PDF를 JSF 애플리케이션에서 팝업으로 표시하는 작업이 있습니다. 그러나 내 모달 패널은 PDF를 렌더링하지 않습니다. 대신 패널의 왼쪽 상단에 작은 진한 회색 상자가 나타납니다.a4j : mediaOutput 렌더링하지 않음 PDF

<rich:column styleClass="viewUserTable"> 
<f:facet name="header"> 
    <h:outputText value="Pdf" /> 
</f:facet> 
<h:outputLink value="#" id="link" style="color:blue;margin: 0 auto;"> 
    Proof 
    <rich:componentControl for="panel" attachTo="link" 
     operation="show" event="onclick" /> 
</h:outputLink> 
<rich:modalPanel id="panel" width="350" height="100"> 
    <f:facet name="header"> 
     <h:outputText value="PDF"></h:outputText> 
    </f:facet> 
    <a4j:mediaOutput element="object" mimeType="application/pdf" 
     id="media" session="false" createContent="#{getMyBean.showPdf}" 
     value="1" style="width:800px; height:600px;" cacheable="false" 
     standby="loading..."> 
    </a4j:mediaOutput> 
</rich:modalPanel> 

가 여기에 내가 <a4j:mediaOutput> 콘텐츠를 만들 내 콩에 전화 드렸습니다 방법입니다 :

여기 내 XHTML 코드입니다.

public void showPdf(OutputStream stream, Object object) throws SQLException, IOException { 

    Blob proof= myObject.getPdf(someValue);//DB call to get the pdf 
    InputStream inStream = proof.getBinaryStream(); 
    int length = -1; 
    byte[] buffer = new byte[4096]; 

    while ((length = inStream.read(buffer)) != -1) { 
     stream.write(buffer, 0, length); 
    } 
} 

나는 <a4j:mediaOutput>에서 value 속성의 중요성 확실하지 오전하지만 비슷한 내용이 DB에서있는 처가 어디서 인터넷에 예를 발견하고 내가 RichFaces 3.3을 사용하고 있습니다 1로 값이 설정 .

답변

0

내 친구가 오늘이 문제로 나에게 와서 너와 같이 해결책을 생각해 보려고 애를 쓴다. 서블릿을 공부 한 후 문제를 해결할 수있었습니다. 단지 OutputStream를 작성하는 것은 당신이 그것을로 출력을 렌더링 할 수 있도록 ServletOutputStream를 작성하고 'FacesContext'throghout를 보내 그래서 충분하지 않은 것 같다

public void showPdf(OutputStream stream, Object object) throws SQLException, IOException { 

    Blob proof = myObject.getPdf(someValue);//DB call to get the pdf 

    FacesContext context = FacesContext.getCurrentInstance(); 
    HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); 
    ServletOutputStream sout = null; 

    response.setContentType("application/pdf"); 
    //set a constant for a name to avoid cache and duplicate files on server 
    response.setHeader("Content-Disposition","filename=fileName_" + (new Date()).getTime() + ".pdf"); 

    response.setHeader("Content-Transfer-Encoding", "binary;"); 
    response.setHeader("Pragma", " "); 
    response.setHeader("Cache-Control", " "); 
    response.setHeader("Pragma", "no-cache;"); 
    response.setDateHeader("Expires", new java.util.Date().getTime()); 
    //Here you will have to pass to total lengh of bytes 
    //as I used a file I called length method 
    response.setContentLength(Long.valueOf( proof.someByteLengthProperty() ).intValue()); 

    sout = response.getOutputStream(); 
    byte[] buf = new byte[4096]; 
    InputStream is = new FileInputStream(proof.getBinaryStream()); 
    int c = 0; 
    while ((c = is.read(buf, 0, buf.length)) > 0) { 
     sout.write(buf, 0, c); 
    } 
    sout.flush(); 
    is.close(); 

} 

: 같은

귀하의 방법을 찾아야한다 다운로드 스트림을 보내는 경우.

관련 문제