如何在网络中嵌入pentaho报表设计器?

时间:2012-12-05 11:21:46

标签: web embed pentaho pentaho-report-designer

我想弄清楚如何在网页上嵌入Pentaho Report Designer报告。

我不仅仅意味着打印出PRD报告的结果 - 我实际上仍想使用PRD设计报告,但是在Web框架内。

有可能吗?

由于

2 个答案:

答案 0 :(得分:0)

您可以使用Pentaho BI Server来部署报告。这意味着另一个应用程序可以通过Web生成报告,甚至BI Server用户也可以生成报告。您可以配置单点登录和其他花哨的东西,以将BI Server用作报表服务器。

编辑报告的唯一方法是通过Pentaho Report Designer,它是一个在桌面上运行的Java应用程序。通过BI Server界面,您只能管理部署的报告。

答案 1 :(得分:0)

如果您不想让服务器pentaho运行来执行此操作,您可以创建一个servlet,输出是html,pdf等的报告内容,这可以使用库pentaho报告设计器来完成可以在同一工具中找到,首先设计报表,然后在您创建的servlet中运行它,作为参数传递位置,输出类型以及您在报表中定义的其他参数

import session.ReportSession;

public class ServletReport扩展了HttpServlet {

public ServletReport() {
}


public void init() {
      ClassicEngineBoot.getInstance().start();

}

protected void doGet(HttpServletRequest req,                          HttpServletResponse resp)  抛出ServletException,       IOException {         generateReport(req,resp);     }

protected void doGet(HttpServletRequest req,    
                       HttpServletResponse resp) throws ServletException,
                                                        IOException {
    generateReport(req, resp);
}
protected void doPost(HttpServletRequest req,    
                       HttpServletResponse resp) throws ServletException,
                                                          IOException {
    generateReport(req, resp);
}


private void generateReport(HttpServletRequest req,
                            HttpServletResponse resp) throws ServletException,
                                                             IOException {
    HttpSession session = req.getSession(true);
    ReportSession values =
        (ReportSession)session.getAttribute("ReportSession");
    //  URL reportDefinitionURL = values.getReportDefinitionURL();

    String reportPath = req.getParameter("Report");
    String contenType = (String)req.getParameter("ContenType");
    //String isMDX = (String)req.getParameter("MDX");
    String url =
        req.getRequestURL().substring(0, req.getRequestURL().indexOf("servletreport")) +
        "Reportes/";
    URL reportDefinitionURL = new URL(url + reportPath);
    MasterReport report = createReportDefinition(reportDefinitionURL);
            try {
             //report.setQ
            Map<String, Object> reportParameters =
                values.getReportParameters();
            if (null != reportParameters) {
                for (String key : reportParameters.keySet()) {
                    report.getParameterValues().put(key,
                                                    (Object)reportParameters.get(key));
                }
            }

        } catch (Exception e) {
            // TODO: Add catch code
            e.printStackTrace();
        }

        OutputStream out = resp.getOutputStream();
        try {
            if (contenType.equalsIgnoreCase("HTML")) {
                resp.setContentType("text/html; charset=\"UTF-8\"");
                HtmlReportUtil.createStreamHTML(report, out);
            } else if (contenType.equalsIgnoreCase("PDF")) {
                resp.setContentType("application/pdf");
                PdfReportUtil.createPDF(report, out);
            } else if (contenType.equalsIgnoreCase("EXCEL")) {
                resp.setContentType("application/vnd.ms-excel");
                ExcelReportUtil.createXLS(report, out);
            } else if (contenType.equalsIgnoreCase("RTF")) {
                resp.setContentType("application/rtf");
                RTFReportUtil.createRTF(report, out);
            }
        } catch (ReportProcessingException rpe) {
            rpe.printStackTrace();
        } finally {
            out.close();
        }

}

//Return a value using EL
private Object executeValueExpression(String valueExpression) {
    FacesContext fctx = FacesContext.getCurrentInstance();
    ELContext elctx = fctx.getELContext();
    Application app = fctx.getApplication();
    ExpressionFactory exprFactory = app.getExpressionFactory();
    ValueExpression valueExpr =
        exprFactory.createValueExpression(elctx, valueExpression,
                                          Object.class);
    return valueExpr.getValue(elctx);
}

private MasterReport createReportDefinition(URL reportDefinitionURL) throws MalformedURLException {
    try {
        ResourceManager resourceManager = new ResourceManager();
        resourceManager.registerDefaults();
        Resource directly =
            resourceManager.createDirectly(reportDefinitionURL,
                                           MasterReport.class);
        MasterReport report = (MasterReport)directly.getResource();
        return report;
    } catch (ResourceException e) {
        e.printStackTrace();
    }
    return null;
}

}