从iText生成的Primefaces在对象组件中显示为空白

时间:2015-07-13 12:33:39

标签: java jsf pdf primefaces outputstream

我需要您的助手在object组件中显示PDF文档的内容。目前,PDF显示为空白。

bean代码是:

    public void  CreatePDF() throws IOException {
      try{
        Document doc = new Document(PageSize.A4, 50, 50, 50, 50);
        OutputStream out = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(doc, out);
        doc.open();

        PdfPTable table = new PdfPTable(1);
        PdfPCell cell = new PdfPCell(new Phrase("First PDF"));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setRunDirection(PdfWriter.RUN_DIRECTION_LTR);
        table.addCell(cell);
        doc.add(table);
        doc.close();
        out.close();

        InputStream in =new ByteArrayInputStream(((ByteArrayOutputStream)out).toByteArray());

                    streamedContent = new DefaultStreamedContent(in, "application/pdf");

                Map<String, Object> session = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
                byte[] b = (byte[]) session.get("reportBytes");
                if (b != null) {
                    streamedContent = new DefaultStreamedContent(new ByteArrayInputStream(b), "application/pdf");
                }         
      }
        catch (Exception e) {
          e.printStackTrace();
                }
    }

和jsf代码:

<p:commandButton value="Show PDF"  actionListener="#{pdf.CreatePDF}"  icon="ui-icon-disk" update=":request:testpdf" />

<p:media id="testpdf" value="#{pdf.streamedContent}" width="190" height="250" player="pdf"/>  

现在我收到了以下错误:

  

]] ServletException的根本原因。 java.lang.NoClassDefFoundError:   javax / el / ValueReference at   org.primefaces.el.InterceptingResolver.getValue(InterceptingResolver.java:51)     at com.sun.el.parser.AstIdentifier.getValue(Unknown Source)at   com.sun.el.parser.AstValue.getValue(未知来源)at   com.sun.el.ValueExpressionImpl.getValue(未知来源)at   com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)     在   org.primefaces.el.ValueExpressionAnalyzer.intercept(ValueExpressionAnalyzer.java:69)     在   org.primefaces.el.ValueExpressionAnalyzer.getExpression(ValueExpressionAnalyzer.java:45)     在   org.primefaces.util.DynamicResourceBuilder.build(DynamicResourceBuilder.java:49)     在   org.primefaces.component.media.MediaRenderer.getMediaSrc(MediaRenderer.java:125)     在   org.primefaces.component.media.MediaRenderer.encodeEnd(MediaRenderer.java:42)     在   javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:884)

0 个答案:

没有答案