2010-11-16 22 views
1

我想在冰面上打印報告,但可以找到適當的方法。請指導我在我的項目中執行相同的操作。在冰面上打印

+0

更具體。 – Sylar 2010-12-01 10:10:13

回答

2

我已經使用ice:outputResource標記讓用戶下載PDF報告文件。該標記的資源屬性應指向實現com.icesoft.faces.context.Resource的託管bean屬性。

+0

嗨! JOTN你的方法工作..我終於把這個測試,發現資源不需要是任何特定的託管bean屬性,但它可以是任何動態資源。謝謝 – venomrld 2010-12-08 03:42:29

2

得到想法後JOTN我終於能夠把它放在一起。

我們可以使用outputresource標記鏈接到任何類型的資源,不僅是靜態資源,還可以動態生成文件(即時)。

讓我們來看看下面的例子:

JSF頁面:

.. 
.. 
<ice:outputResource id="outputResource1" attachment="false" fileName="File1.pdf" label="Click to download attachment" mimeType="application/pdf" rendered="true" resource="#{ReportParam01.reportfilers}" shared="false"/> 
.. 
.. 

在這裏,我觀察到,outputresource鏈接不會出現,直到實際產生的文件(我的飛行文件)。

讓我們假設我們希望動態生成pdf文件。以下步驟將將其鏈接到上述輸出資料。

託管Bean:

public class....{ 
    .... 
    // This is the resource linked to the <ice:outputresource> tag. 
    // Encapsulation has been done to link it. 
    Reource reportfilers; 
    .... 

    public void createDocument() { 
     Document reportDoc = new Document(PageSize.A4); 
     File file1 = new File("Report.pdf"); 
     PdfWriter.getInstance(reportDoc, new FileOutputStream(f)); 
     // writing to pdf code continues 
     reportfilers = new FileResource(file1); 
    } 
    .... 
    .... 
} 

調用上面的方法(如果它有沒有例外)將鏈接顯示出來,用戶可以下載該文件。