1

I am trying to figure out how to embed a Pentaho Report Designer report on a web page.

I don't simply mean printing out the results of a PRD report--I want to actually still design the report using PRD, but within a web framework.

Is it possible to do that?

Thanks

zurfyx
  • 31,043
  • 20
  • 111
  • 145
Andiyono
  • 11
  • 1
  • 4

2 Answers2

0

You can use Pentaho BI Server to deploy your reports. This mean another app can generate reports through the web or even the BI Server users can generate reports. You can configure single sign on and other fancy stuff to use the BI Server as a report server.

The only way to edit your reports is through Pentaho Report Designer which is a Java application that runs on your desktop. Through the BI Server interface you can only manage the reports deployed.

Reichert
  • 133
  • 5
0

if you do not want to have the server pentaho running to do this, you can make a servlet that the output is the contents of a report in html, pdf, ect., this can be accomplished using libraries pentaho report designer the can found within the same tool, first you design the report and then run it in the servlet that you created, passed as a parameter the location, the type of output, and additional parameters you define in the report

import session.ReportSession;

public class ServletReport extends HttpServlet {

public ServletReport() {
}


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

}

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws 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;
}

}