使用jsf在ireport中集成报告

时间:2010-11-07 04:56:53

标签: jsf jasper-reports

你好所有..
我有问题用jsf中的jasper report / ireport插件创建pdf格式报告?
我在jasper报告中做了一个报告,但是我无法将它与jsf整合为create pdf格式..
谢谢你的帮助......

1 个答案:

答案 0 :(得分:1)

可以这样做。在指向bean的操作方法的页面上添加h:commandLink

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

在您的bean中,您应该生成报告并将其写入响应的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;

  }
}