# Integration with Reporting Tool

To integrate **ONEWEB** with external **Reporting Tools**, the platform follows a structured approach that separates **data preparation**, **report design**, and **report generation**.\
This integration enables applications to generate reports dynamically in formats such as **PDF** or **Excel**, without persisting files on the server.

***

### Reporting Integration Architecture

Integration with reporting tools in ONEWEB requires the implementation of **three core components**:

1. **Report Servlet**\
   A Java servlet responsible for generating the output report document (PDF, Excel, etc.)
2. **Report Form**\
   A report template designed using a supported reporting tool (for example, JasperReports)
3. **Entity for Data Retrieval**\
   An entity used to search and prepare data, then invoke the report servlet with the required parameters

Together, these components form a flexible reporting pipeline.

***

#### Reporting Architecture Overview

The following diagram illustrates the overall reporting architecture in ONEWEB:

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2Fj2R7wfXposRlr2WhvAI4%2F0?alt=media" alt=""><figcaption></figcaption></figure>

***

### Sample Use Case: Generate PDF Report Using JasperReports

The example below demonstrates how to generate a **PDF report** using a **Jasper (.jrxml)** report template through a Java servlet.

***

### Step 1: Prepare Required Libraries

Prepare and include the necessary external JAR files in your project\
(*`x.x.x` represents the version used by your project*).

Required libraries:

* `commons-beanutils-x.x.x.jar`
* `commons-collections-x.x.x.jar`
* `commons-digester-x.x.x.jar`
* `commons-logging-x.x.x.jar`
* `jasperreports-x.x.x.jar`
* `jfreechart-x.x.x.jar`

Optional libraries:

* `groovy-all-x.x.x.jar`\
  \&#xNAN;*(Required if the report language is Groovy)*
* `iText-x.x.x.jar`\
  \&#xNAN;*(Required for PDF export)*
* `poi-x.x.x.jar`\
  \&#xNAN;*(Required for Excel export)*

***

### Step 2: Design the Report Form

Create the report template using a supported reporting tool.\
This example uses **iReport** to design the `.jrxml` file.

Recommended resources:

* **iReport Designer**\
  <https://community.jaspersoft.com/wiki/ireport-designer-tutorials-help>
* **Crystal Reports**\
  <https://www.tutorialspoint.com/crystal_reports/>
* **JasperReports**\
  <https://www.tutorialspoint.com/jasper_reports/>

The output of this step is a `.jrxml` report definition file.

***

### Step 3: Develop Report Generation Servlet

Create a Java servlet that:

* Compiles the Jasper report
* Retrieves data using a database connection
* Generates the report output
* Streams the result directly to the client

#### Example: Generate PDF Report

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

    try {
        String path = "\\imports\\report\\oneweb_report.jrxml";

        JasperReport jReport =
        JasperCompileManager.compileReport(path);

        // Database connection via JNDI
        Connection con = /* jdbc/application */;

        // Prepare report parameters
        Map paramMap = new HashMap();
        paramMap.put(
            "REPORT_PARAMETER",
            request.getParameter("REPORT_PARAMETER")
        );

        // Generate report
        JasperPrint jPrint =
            JasperFillManager.fillReport(jReport, paramMap, con);

        // Output as PDF
        response.setContentType("application/pdf");
        ServletOutputStream out =
            response.getOutputStream();

        JasperExportManager.exportReportToPdfStream(
            jPrint,
            out
        );

    } catch (Exception ex) {
        // Exception handling
        // TODO: logging and error response
    }
}
```

#### Key Characteristics

* Uses JNDI datasource: `jdbc/application`
* Does not store the generated file on the server
* Streams the report output directly to the client
* Supports parameterized reports

***

### Step 4: Invoke Report via Entity

Create an **Entity** that calls the report servlet.

Implementation steps:

* Use **Entity Action** to invoke the servlet
* Add JavaScript to prepare the request URL and parameters
* Call the servlet using the report URL

#### Example URL

```
http://host:port/report?name=reportName&REPORT_PARAMETER=zzz
```

This allows reports to be generated dynamically in response to user interactions.

***

### Summary

By integrating ONEWEB with external reporting tools:

* Reports can be generated dynamically at runtime
* Output formats such as **PDF** and **Excel** are supported
* Report files do not need to be stored on the server
* Data retrieval and report generation are clearly separated
* The solution scales for both simple and complex reporting needs

This integration approach enables flexible, enterprise‑grade reporting while keeping the application architecture clean and maintainable.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onewebstack.com/oneweb-platform-th/building-apps/ui-page-designer/ux-ui-components/report/integration-with-reporting-tool.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
