Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: Passing parameter via api when loading a .prpt in a servlet

  1. #1

    Default Passing parameter via api when loading a .prpt in a servlet

    I have created a report using the Pentaho report designer for a query that accepts a parameter. The report designer did execute the query properly by prompting for the parameter value when i executed the report.

    Now i am trying to run it in my jboss servlet. But I am highly confused not understanding how to pass the parameter in the servlet code.

    My servlet code is given below. This is the code that displayed me the report for a .prpt report that did not have any parameter to be passed.

    Please somebody help in telling what change need to be made to make this running by accepting the parameter.....


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    ResourceManager manager = new ResourceManager();
    manager.registerDefaults();

    String reportPath = "file:" +
    this.getServletContext().getRealPath("applicant.prpt");

    try {
    Resource res = manager.createDirectly(new URL(reportPath),
    MasterReport.class);
    MasterReport report = (MasterReport) res.getResource();
    HtmlReportUtil.createStreamHTML(report, response.getOutputStream());

    } catch (Exception e) {
    e.printStackTrace();
    }
    }

  2. #2
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    Code:
    report.getParameterValues().put ("parameterName", parameterValue);
    Parameter are strongly typed, so you have to pass the correct object types in. Multi-select parameter require arrays.

    If you need a generic solution for all your reports, then you can access parameter definitions via

    Code:
    ReportParameterDefinition parameters = report.getParameterDefinition();
    This is a list of parameter definition entries, either a "PlainParameter" or a "DefaultListParameter". The second this you get from the parameter-definition is the ReportParameterValidator, which allows you to validate parameter sets to see whether a report would run. It also gives you error messages keyed by the parameter name if needed.

    PS: If you load from a file, give a "File" object instead of a URL. It make parsing a lot easier.

    Code:
    String reportPath = this.getServletContext().getRealPath("applicant.prpt");
    
    try {
    Resource res = manager.createDirectly(new File(reportPath), MasterReport.class);
    ...
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.