2010-11-07 93 views
0

hallo all ..
我有一个问题,以jsf中的jasper报告/ ireport插件创建pdf格式报告?
我所做的碧玉报告的报告,但我不能将其与JSF用于创建PDF格式的整合..
感谢您的帮助..ireport与jsf集成报告

回答

1

难道能这样做。在一个页面指向添加h:commandLink到你的bean的操作方法:

<h:commandLink value="download report" action="#{myBean.downloadReport}" /> 

在你豆你应该生成报表,并将其写入到响应的OutputStream

public class MyBean { 

    public String downloadReport() { 

    // get HttpServletResponse 
    FacesContext context = FacesContext.getCurrentInstance(); 
    HttpServletResponse response = 
     (HttpServletResponse) context.getExternalContext().getResponse(); 

    // set correct content type 
    response.setContentType("application/pdf"); 

    // get OutputStream 
    OutputStream stream = response.getOutputStream(); 

    // TODO: generate PDF and write the report to this output stream 

    // mark response as completed 
    context.responseComplete(); 
    return null; 

    } 
} 
+0

OWH我undurstand它简单的代码。谢谢..但是,我在我的报告中访问了数据库..在这个报告中,我必须发送一个变量来访问数据库中的某些数据。我如何通过JSF表单向我的报告中添加变量(ireport中的参数)? – irwan 2010-11-09 02:50:06

+0

我不是Jasper Reports的真正专家。您应该深入了解他们的API。也许这个例子有助于:http://seamframework.org/61907.lace – chkal 2010-11-09 07:14:35

+0

非常感谢你..这是非常helpul .. – irwan 2010-11-11 02:46:36