WaveMaker Docs

WaveMaker Docs

  • Get started
  • Widgets
  • Mobile
  • How-to
  • Enterprise
  • Releases
  • Blog
  • Sign-in

›Developer options

How-to-documents

  • How-to Wiki
  • WaveMaker Best Practices

App solution

  • Creating a Registration Page
  • Support for Password Encryption
  • Error Handling in WaveMaker App
  • Leaving Page with Unsaved Changes
  • Micro frontend using iframes
  • Enabling PWA

UI design

  • Passing Parameters to Pages
  • Passing Parameters to Partial Page
  • Accessing Script
  • Use Static Variable to pass data between pages
  • Customise Login Page
  • Incorporating Additional Icons
  • Change Icon Color on Condition
  • Change Icon for the Global Spinner
  • Changing Default Favicon
  • Changing App Logo
  • Changing Page Title
  • Customise App Style
  • How to use Conditional Class Property
  • How to use Conditional Style Property
  • Customize an Existing Theme
  • Adjust Left Navigation Width
  • Customizing Theme
  • Enable SPA
  • Choose Widget Template and Layout
  • Widget Template and Icons
  • Custom Template for Widgets
  • Apply Custom Data Formatter

Nav & Dropdown

  • Dynamic Menu based on User Role
  • Restricting Menu Items based on the User Role
  • Localization for Dropdown Menu

Localization

  • Localization in WaveMaker Apps
  • Setting Language and Date Format
  • Localization Using Select Locale
  • Localization of Error Messages

Security

  • SAML Integration - OneLogin
  • SAML Integration - ADFS
  • OpenID Integration - Azure AD
  • Custom Security using Google OAuth Prefab
  • Multiple Security Provider Implementation
  • Customizing Post Authentication Handlers
  • Configuring Content-Security-Policy
  • Configuring MTLS

Databases

  • Queries with Dynamic Where Clause
  • Connect To Azure SQL Server
  • Recommended JDBC Driver Versions for Databases
  • How to fetch more than the default number(100) of records from database?
  • How To: One-to-Many Relationship
  • Working with Temporals
  • Connect To AWS Redshift Database
  • Connect To SAP Hana Cloud Database
  • Transactional History of Entity
  • Row-Level Security using DB Event Listeners
  • Validations using CRUD Listeners
  • Custom Logic DB Event Listeners
  • Connect to MySQL database using SSL
  • How to Switch MariaDB to MySQL Connector

Web services

  • Using App Environment Properties
  • Consuming an Existing WaveMaker API
  • Using POST method to send data to a REST API
  • Request-Response Processing for REST Services
  • How to Intercept Request and Response of all API Calls in One Place
  • WebSocket Usage - Chatroom App
  • UI for API Server-side Pagination
  • Working with API with different pagination formats

Java services

  • Sending Email using WaveMaker Connector
  • Implementing Forgot Password feature using Java Service
  • Accessing REST APIs from Java Service
  • Scheduling a Java Service
  • Integrating JUnit Tests for WaveMaker Application
  • ORM Artifacts
  • Pre-Post Processing for Database Service APIs
  • Accessing Logged-in User Details using Java Service
  • Design a workflow in Camunda BPM and integrate into a WaveMaker app
  • Integrate Azure File Storage
  • Insert Data from Excel into Database
  • Integrate Amazon S3 into WaveMaker App
  • Integrate Twilio Connector
  • Integrate OTP (One-Time Passcode) Verification with WaveMaker App

Variables

  • Using Filter Conditions on Variable
  • Using Live Variable APIs
  • Using Notification Actions
  • Using Navigation Action
  • Using Variables for Queries and Procedure
  • Using Service Variable in a Form
  • Using Filter Criteria for a Data and Live Widgets
  • Using Filter Criteria for a Database CRUD Variable

JavaScript

  • Using JavaScript in Binding
  • Using JavaScript from External URL
  • Using JavaScript to loop a command
  • Using function for evaluating conditions

Developer options

  • Synchronizing WaveMaker Apps with IDEs
  • Synchronizing Java Services Controller
  • Integrating Amazon Cognito for User Authentication
  • Integrating Sample Jasper Report in WaveMaker Application
  • How to generate PDF File using Jasper Reports
  • Upgrading an App from WaveMaker 9.x to WaveMaker 10.0
  • App Migration from WaveMaker 9x to 10x
  • Setup Fusion Reactor for Debugging Issues

Deployment

  • SSL Termination in LoadBalancer

Mobile App Solutions

  • Notify users about new update

Mobile gesture

  • Setting Swipe Gestures on a List Widget
  • Working with Pull to Refresh

Mobile widgets

  • Using Search Widget within the Navbar

Mobile UI design

  • Setting Splashscreen Images and App Icons
  • Using Cordova Plugins
  • Designing Tablet Views in Mobile Project
  • Sliding left navigation for Mobile App
  • Mobile App using Bar code
  • Custom Date Picker in Mobile

Cards

  • Capturing Card Items

DataTable

  • Customising Data Table Row Action
  • How to Configure Row Expansion in a Data Table
  • Using Widgets to represent Data Table Columns
  • View Master-Detail Data Records using Data Table
  • Add Master-Detail records using Data Table
  • Export Data from Data Table
  • Export Data from Data Table - 2
  • Setting Blob Filename
  • Dynamic Data Tables
  • Customize Dynamic Datatable
  • Data Table Column bound to Query
  • Combining Columns in Data Table
  • Custom Styling Data Table Columns & Rows
  • Formatting Data Table Columns
  • Concurrency and Record Locking in WaveMaker
  • Edit DataTable records bound to Query API

List

  • Creating an Employee List grouped by City
  • Creating an Employee List grouped by Birth Month and City
  • OnRender Event
  • Including a Data Table within a List
  • Building an Editable List
  • Building Cascading Lists
  • Accessing List Items
  • Localization of Data Table Column Headings

Forms

  • Using Live Form
  • How Tos: Form
  • Building Tabbed Live Form
  • How Tos: Live Form
  • Linking Live Form with another Widget for Input
  • Handling Related Fields in a Live Form
  • How to Get Validation Messages from a Form
  • Adding Master-Detail records in the same transaction
  • Submit Parent and Child Records in a Single Transaction
  • Submit Parent and Child Records in a Single Transaction using Form and Data Table
  • Using Cascading Select & Autocomplete for Live Form Fields
  • Using Cascading Select within Live Form
  • Using cascading Filter to populate Live Form
  • Using Wizard for Master-Detail Live Form
  • Copy to Clipboard
  • Create a form with multiple wizard steps
  • Smart Forms: Conditional Flows for form Widget

Calendar

  • How Tos: Calendar
  • Calendar Usage - Create an Event
  • Calender Usage - Google Calendar Integration

CheckboxSet

  • CheckboxSet to Filter List data

FileUpload

  • FileUpload - Basic Usage
  • File Upload Widget Operations
  • Upload File & Save in Database
  • File Upload & Blob Data
  • File Upload - Custom Directory
  • Accessing File Upload from Java Code
  • Upload Files from Live Form & Form

Radioset

  • Radioset to Filter a List

Rating

  • Building Rating Widget using Static Data
  • Building Rating Widget using Static Variable
  • Build Rating Widget using Model Variable
  • Building an Interactive Rating Widget

Select

  • Configuring Select Widget from a Static List of Values
  • Configuring Select Widget from a Static Variable
  • Configuring Select Widget from a Variable
  • Configuring Select Widget using Display and Data Fields
  • Configuring Select Widget from Database Fields
  • Configuring Cascading Select
  • Selection Widgets - Use Case

Progress Circle

  • Using Progress Circle Widget

Charts

  • Working with Charts
  • Display User Selection in another Widget
  • Handling Dynamic Data
  • Custom Data

Richtext Editor

  • Adding Custom Fonts to Richtext Editor

Live filter

  • Applying Live Filter to a Data Table or a Chart
  • Building a Multiple Selection Live Filter
  • Building a Range Live Filter

Container

  • Setting partial page content for Accordion within a List
  • Setting partial page content for Panel within a List using JavaScript
  • How Tos: Wizard
  • Dynamic Tabs and Accordions

Tree

  • Tree using Static Variable
  • Tree using Java Service
  • Tree using Dynamic Tree

Prefabs

  • Creating Partials in a Prefab
  • Create Prefab using Third Party UI Widgets
  • Create a Simple Prefab
  • Create Prefab Using D3 & NVD3 Charts
  • Create Prefab Using D3 Library DataMaps
  • Create Prefab using JQuery Plugin
  • Create Prefab using Angular Module
  • Create Prefab using Angular, React Components
  • Azure OAuth Prefab Integration

Team Poral Configure Vcs

  • Configure Azure Repos In CodeRepository
Edit

How to generate PDF File using Jasper Reports


Step 1: Import the jasper-report-connector to project

  1. Download the latest jasper-report-connector zip from here
  2. Import the downloaded jasper-report-connector zip into your project using the Import Resource option to the Connector folder.

Step 2: Create a Java Service

  1. Create a Java Service, named JasperReportService
  2. Add import statement for jasper-report-connector interface.
    import com.wavemaker.connector.jasper.JasperConnector;
    
  3. Autowire the jasper report service
    @Autowired
    private JasperConnector jasperConnector;
    

We can generate the Jasper Reports using various data sources in WaveMaker projects. This document will present the data base and Api data as the datasources.

Example 1: Generating Jasper Report from a imported DataBase:

  1. Build your report using Jasper Studio, which enables you to build and customize look and feel of the report. Once you design the report export the reportxml(.jrxml) and import into WaveMaker project using Import Resource to the ${ServiceName}/src/ folder

  2. The following sample report jrxml is provided for your reference which loads the data from hrdb Employee table and generates the report.

    <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports
         http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"
               name="My first report" pageWidth="595" pageHeight="842" columnWidth="535"
               leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <queryString language="SQL">
         <![CDATA[select * from employee]]>
    </queryString>
    <field name="EMP_ID" class="java.lang.Integer">
         <fieldDescription><![CDATA[EMP_ID]]></fieldDescription>
    </field>
    <field name="firstname" class="java.lang.String">
       <fieldDescription><![CDATA[firstname]]></fieldDescription>
    </field>
    <field name="lastname" class="java.lang.String">
         <fieldDescription><![CDATA[lastname]]></fieldDescription>
    </field>
    <field name="USERNAME" class="java.lang.String">
         <fieldDescription><![CDATA[USERNAME]]></fieldDescription>
    </field>
    <field name="ROLE" class="java.lang.String">
         <fieldDescription><![CDATA[ROLE]]></fieldDescription>
    </field>
    <field name="city" class="java.lang.String">
         <fieldDescription><![CDATA[city]]></fieldDescription>
    </field>
    <title>
         <band height="70">
             <line>
                 <reportElement x="0" y="0" width="515" height="1"/>
             </line>
             <staticText>
                 <reportElement x="0" y="10" width="515" height="30"/>
                 <textElement textAlignment="Center">
                     <font size="22" isBold="true"/>
                 </textElement>
                 <text><![CDATA[Employees By City]]></text>
             </staticText>
         </band>
    </title>
    <pageHeader>
         <band height="140">
             <staticText>
                 <reportElement x="65" y="16" width="424" height="50"/>
                 <textElement textAlignment="Center">
                     <font size="26" isBold="true"/>
                 </textElement>
                 <text><![CDATA[Employees Report]]></text>
             </staticText>
         </band>
    </pageHeader>
    <columnHeader>
         <band height="18">
             <staticText>
                 <reportElement mode="Opaque" x="0" y="0" width="80" height="18"
                               forecolor="#FFFFFF" backcolor="#999999"/>
                 <textElement>
                     <font size="12"/>
                 </textElement>
                 <text><![CDATA[ID]]></text>
             </staticText>
             <staticText>
                 <reportElement mode="Opaque" x="80" y="0" width="80" height="18"
                               forecolor="#FFFFFF" backcolor="#999999"/>
                 <textElement>
                     <font size="12"/>
                 </textElement>
                 <text><![CDATA[FIRSTNAME]]></text>
             </staticText>
             <staticText>
                 <reportElement mode="Opaque" x="160" y="0" width="80" height="18"
                               forecolor="#FFFFFF" backcolor="#999999"/>
                 <textElement>
                     <font size="12"/>
                 </textElement>
                 <text><![CDATA[LASTNAME]]></text>
             </staticText>
             <staticText>
                 <reportElement mode="Opaque" x="240" y="0" width="80" height="18"
                               forecolor="#FFFFFF" backcolor="#999999"/>
                 <textElement>
                     <font size="12"/>
                 </textElement>
                 <text><![CDATA[USERNAME]]></text>
             </staticText>
             <staticText>
                 <reportElement mode="Opaque" x="320" y="0" width="80" height="18"
                               forecolor="#FFFFFF" backcolor="#999999"/>
                 <textElement>
                     <font size="12"/>
                 </textElement>
                 <text><![CDATA[ROLE]]></text>
             </staticText>
             <staticText>
                 <reportElement mode="Opaque" x="400" y="0" width="80" height="18"
                               forecolor="#FFFFFF" backcolor="#999999"/>
                 <textElement>
                     <font size="12"/>
                 </textElement>
                 <text><![CDATA[CITY]]></text>
             </staticText>
         </band>
    </columnHeader>
    <detail>
         <band height="20">
             <textField hyperlinkType="None">
                 <reportElement x="0" y="0" width="80" height="20"/>
                 <textElement>
                     <font size="12"/>
                 </textElement>
                 <textFieldExpression class="java.lang.Integer"><![CDATA[$F{EMP_ID}]]>
                 </textFieldExpression>
             </textField>
             <textField hyperlinkType="None">
                 <reportElement x="80" y="0" width="80" height="20"/>
                 <textElement>
                     <font size="12"/>
                 </textElement>
                 <textFieldExpression class="java.lang.String"><![CDATA[$F{firstname}]]>
                 </textFieldExpression>
             </textField>
             <textField hyperlinkType="None">
                 <reportElement x="160" y="0" width="80" height="20"/>
                 <textElement>
                     <font size="12"/>
                 </textElement>
                 <textFieldExpression class="java.lang.String"><![CDATA[$F{lastname}]]>
                 </textFieldExpression>
             </textField>
             <textField hyperlinkType="None">
                 <reportElement x="240" y="0" width="80" height="20"/>
                 <textElement>
                     <font size="12"/>
                 </textElement>
                 <textFieldExpression class="java.lang.String"><![CDATA[$F{USERNAME}]]>
                 </textFieldExpression>
             </textField>
             <textField hyperlinkType="None">
                 <reportElement x="320" y="0" width="80" height="20"/>
                 <textElement>
                     <font size="12"/>
                 </textElement>
                 <textFieldExpression class="java.lang.String"><![CDATA[$F{ROLE}]]>
                 </textFieldExpression>
             </textField>
             <textField hyperlinkType="None">
                 <reportElement x="400" y="0" width="80" height="20"/>
                 <textElement>
                     <font size="12"/>
                 </textElement>
                 <textFieldExpression class="java.lang.String"><![CDATA[$F{city}]]>
                 </textFieldExpression>
             </textField>
         </band>
    </detail>
    </jasperReport>
    
  3. Place the .jrxml file in the java service src folder as shown below:

  4. Import Sample HRDB database into the project

  5. Autowire the imported DataBase dataSource bean in to the created java serice

    @Autowired
    @Qualifier("hrdbDataSource")
    private WMDataSource dataSource;
    
    note

    Here Qualifier name is ${databaseServiceName}DataSource

  6. Java service code to generate Jasper Report PDF from hrdb Employee table

    import java.io.*;
    import java.util.HashMap;
    import javax.servlet.http.HttpServletResponse;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.web.client.RestTemplate;
    
    
    import com.wavemaker.runtime.security.SecurityService;
    import com.wavemaker.runtime.service.annotations.ExposeToClient;
    import com.wavemaker.runtime.service.annotations.HideFromClient;
    
    
    //import com.wavemaker.runtime.file.model.DownloadResponse;
    //import com.wavemaker.runtime.file.model.Downloadable;
    
    import com.wavemaker.runtime.commons.file.model.DownloadResponse;
    import com.wavemaker.runtime.commons.file.model.Downloadable;
    
    
    import com.wavemaker.connector.jasper.JasperConnector;
    import com.wavemaker.connector.jasper.JasperExportType;
    import com.wavemaker.runtime.data.datasource.WMDataSource;
    //import com.jasperreportconnector_integratio.jasperreportservice.model.*;
    
    
    @ExposeToClient
    public class JasperReportService {
      
      private static final Logger logger = LoggerFactory.getLogger(JasperReportService.class);
      
      @Autowired
      private JasperConnector jasperConnector;
      
      @Autowired
      @Qualifier("hrdbDataSource")
      private WMDataSource dataSource;
      
      
      
      public Downloadable generatePDFReportFromDataSource() {
          
          logger.info("Calling connector to generate the jasperRepoet");
          ByteArrayOutputStream pdfReportStream = (ByteArrayOutputStream) jasperConnector.generateReport(JasperExportType.PDF, 
          "emp.jrxml", new HashMap<>(), dataSource);
          
          DownloadResponse downloadableResponse = new DownloadResponse(new ByteArrayInputStream(pdfReportStream.toByteArray()), "application/pdf", "jasper.pdf");
    
          downloadableResponse.setInline(false);
    
          return downloadableResponse;
      }
    }
    
    note

    Here we can use various export types defined in JasperExportType class

    public enum JasperExportType {
        HTML, PDF, XLS, CSV, DOC
    }
    

Example 2: Generating Jasper Report by consuming the API Data

  • To generate PDF file using Jasper Reports, data needs to be consumed from an external REST API. This data should be passed to the jasper report to genereate the PDF file.

  • Steps to generate PDF file using Jasper reports are as follows:

  1. Take a Random User Rest api.

  2. The Rest api response JSON output looks typically as follows:

    {
      "results":[
          {
            "gender":"female",
            "name":{
                "title":"Mrs",
                "first":"سوگند",
                "last":"حیدری"
            },
            "location":{
                "street":{
                  "number":7708,
                  "name":"کلاهدوز"
                },
                "city":"همدان",
                "state":"قزوین",
                "country":"Iran",
                "postcode":19937,
                "coordinates":{
                  "latitude":"32.0062",
                  "longitude":"75.8685"
                },
                "timezone":{
                  "offset":"-10:00",
                  "description":"Hawaii"
                }
            },
            "email":"swgnd.hydry@example.com",
            "login":{
                "uuid":"82a1cfc8-1f05-4022-87af-2c609ad71d72",
                "username":"yellowcat820",
                "password":"perkins",
                "salt":"9ctdihFC",
                "md5":"35aa186cb7b284ef325d074f15b92c14",
                "sha1":"710d7669e9a5e7acffd81c52207b6e1735542017",
                "sha256":"2c9bd5e4c2d1f2b4868cb4697928c326399b4043f5fc9cb0d577d3fc050c4dc8"
            },
            "dob":{
                "date":"1965-05-21T10:23:03.245Z",
                "age":55
            },
            "registered":{
                "date":"2002-05-12T01:19:23.992Z",
                "age":18
            },
            "phone":"068-40841829",
            "cell":"0900-366-6250",
            "id":{
                "name":"",
                "value":null
            },
            "picture":{
                "large":"https://randomuser.me/api/portraits/women/58.jpg",
                "medium":"https://randomuser.me/api/portraits/med/women/58.jpg",
                "thumbnail":"https://randomuser.me/api/portraits/thumb/women/58.jpg"
            },
            "nat":"IR"
          },
          {
            "gender":"male",
            "name":{
                "title":"Mr",
                "first":"Abdullahi",
                "last":"Lyngvær"
            },
            "location":{
                "street":{
                  "number":4218,
                  "name":"Fred. Olsens gate"
                },
                "city":"Vik",
                "state":"Vestfold",
                "country":"Norway",
                "postcode":"5063",
                "coordinates":{
                  "latitude":"59.0651",
                  "longitude":"-76.8243"
                },
                "timezone":{
                  "offset":"-5:00",
                  "description":"Eastern Time (US & Canada), Bogota, Lima"
                }
            },
            "email":"abdullahi.lyngvaer@example.com",
            "login":{
                "uuid":"f015aaa3-80c4-4083-a3ef-5cbf1a383a35",
                "username":"bluefrog472",
                "password":"pang",
                "salt":"US9gPmIm",
                "md5":"a5844013475424d724302f2991d9ed77",
                "sha1":"5c6b17606201f0b286c541f9b1f94755419cbbcd",
                "sha256":"3f93d57080fed6bb7dc0ad4489f236b6d972f8d1764703cf3dd0b6818dfee529"
            },
            "dob":{
                "date":"1993-07-18T04:05:16.188Z",
                "age":27
            },
            "registered":{
                "date":"2004-02-11T17:09:18.310Z",
                "age":16
            },
            "phone":"25377095",
            "cell":"43846252",
            "id":{
                "name":"FN",
                "value":"18079344164"
            },
            "picture":{
                "large":"https://randomuser.me/api/portraits/men/64.jpg",
                "medium":"https://randomuser.me/api/portraits/med/men/64.jpg",
                "thumbnail":"https://randomuser.me/api/portraits/thumb/men/64.jpg"
            },
            "nat":"NO"
          },
          {
            "gender":"female",
            "name":{
                "title":"Miss",
                "first":"Lumi",
                "last":"Kujala"
            },
            "location":{
                "street":{
                  "number":2761,
                  "name":"Esplanadi"
                },
                "city":"Haapajärvi",
                "state":"Southern Savonia",
                "country":"Finland",
                "postcode":48347,
                "coordinates":{
                  "latitude":"-15.5371",
                  "longitude":"145.3695"
                },
                "timezone":{
                  "offset":"+11:00",
                  "description":"Magadan, Solomon Islands, New Caledonia"
                }
            },
            "email":"lumi.kujala@example.com",
            "login":{
                "uuid":"1a096bc0-f936-4d69-b934-1869861f410c",
                "username":"browngoose244",
                "password":"cleo",
                "salt":"jZBCJ9AU",
                "md5":"337382dc4a33f6ad9d83d8d60e6c61df",
                "sha1":"e5a4a0ec540efd422da964b8e005bf5640afc31a",
                "sha256":"938e52af41074bf3c59a9d780404517fd87e3f326bd8dcce22b75de4679fbc55"
            },
            "dob":{
                "date":"1949-09-10T16:53:58.541Z",
                "age":71
            },
            "registered":{
                "date":"2014-05-31T22:17:18.262Z",
                "age":6
            },
            "phone":"04-001-698",
            "cell":"045-870-79-48",
            "id":{
                "name":"HETU",
                "value":"NaNNA740undefined"
            },
            "picture":{
                "large":"https://randomuser.me/api/portraits/women/4.jpg",
                "medium":"https://randomuser.me/api/portraits/med/women/4.jpg",
                "thumbnail":"https://randomuser.me/api/portraits/thumb/women/4.jpg"
            },
            "nat":"FI"
          }
      ],
      "info":{
          "seed":"f58ab75d5544db7a",
          "results":3,
          "page":1,
          "version":"1.3"
      }
    }
    
  1. Design a jasper report for the above data. The following is a sample report file. Which we need to import into the project using Import Resource to the ${Service}/src/ folder.

      <?xml version="1.0" encoding="UTF-8"?>
      <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Report" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="81afe112-ee1b-4443-8d1c-cb6d9ab95dd8">
          <property name="com.jaspersoft.studio.data.defaultdataadapter" value="JsonArrayDataAdapter.xml"/>
          <subDataset name="results" uuid="4563e834-a9e5-43b5-9f0a-824948c73c73">
              <field name="Email" class="java.lang.String">
                  <fieldDescription><![CDATA[email]]></fieldDescription>
              </field>
              <field name="Gender" class="java.lang.String">
                  <fieldDescription><![CDATA[gender]]></fieldDescription>
              </field>
              <field name="Phone" class="java.lang.String">
                  <fieldDescription><![CDATA[phone]]></fieldDescription>
              </field>
          </subDataset>
          <queryString language="json">
              <![CDATA[]]>
          </queryString>
          <field name="Email" class="java.lang.String">
              <fieldDescription><![CDATA[email]]></fieldDescription>
          </field>
          <field name="Gender" class="java.lang.String">
              <fieldDescription><![CDATA[gender]]></fieldDescription>
          </field>
          <field name="Phone" class="java.lang.String">
              <fieldDescription><![CDATA[phone]]></fieldDescription>
          </field>
          <title>
              <band height="70">
                  <line>
                      <reportElement x="0" y="0" width="515" height="1"/>
                  </line>
                  <staticText>
                      <reportElement x="0" y="10" width="515" height="30"/>
                      <textElement textAlignment="Center">
                          <font size="22" isBold="true"/>
                      </textElement>
                      <text><![CDATA[Random Users Data]]></text>
                  </staticText>
              </band>
          </title>
          <pageHeader>
              <band height="140">
                  <staticText>
                      <reportElement x="65" y="16" width="424" height="50"/>
                      <textElement textAlignment="Center">
                          <font size="26" isBold="true"/>
                      </textElement>
                      <text><![CDATA[Users Report]]></text>
                  </staticText>
              </band>
          </pageHeader>
          <columnHeader>
              <band height="23">
                  <staticText>
                      <reportElement mode="Opaque" x="0" y="3" width="535" height="15"
                                    forecolor="#FFFFFF" backcolor="#999999"/>
                      <box>
                          <bottomPen lineWidth = "1.0" lineColor = "#CCCCCC" />
                      </box>
                      <text>
                          <![CDATA[]]>
                      </text>
                  </staticText>
                  <staticText>
                      <reportElement x = "400" y = "3" width = "121" height = "15" />
    
                      <textElement textAlignment = "Center" verticalAlignment = "Middle">
                          <font isBold = "true" />
                      </textElement>
    
                      <text><![CDATA[GENDER]]></text>
                  </staticText>
                  <staticText>
                      <reportElement x="10" y="3" width="121" height="15" />
                      <textElement textAlignment = "Center" verticalAlignment = "Middle">
                          <font isBold ="true"/>
                      </textElement>
                      <text><![CDATA[E-MAIL]]></text>
                  </staticText>
                  <staticText>
                      <reportElement x="200" y="0" width="121" height="15"
                                    forecolor="#FFFFFF" backcolor="#70A9A9"/>
                      <textElement textAlignment = "Center" verticalAlignment = "Middle">
                          <font isBold = "true" />
                      </textElement>
                      <text><![CDATA[PHONE]]></text>
                  </staticText>
              </band>
          </columnHeader>
          <detail>
              <band height="25" splitType="Stretch">
                  <componentElement>
                      <reportElement x="0" y="1" width="333" height="20" uuid="c3237c70-6b2e-43e3-aa21-5092d8b91afc"/>
                      <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                          <datasetRun subDataset="results" uuid="f5fdc6a3-736f-43ce-b549-cd7332d19eb8">
                              <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("results")]]></dataSourceExpression>
                          </datasetRun>
                          <jr:listContents height="25" width="600">
                              <textField>
                                  <reportElement x = "50" y = "3" width = "121" height = "15" uuid="07e3ff2a-3832-4b06-9275-cb1ee8e51cfe"/>
                                  <textFieldExpression><![CDATA[$F{Email}]]></textFieldExpression>
                              </textField>
                              <textField>
                                  <reportElement x="400" y="3" width="121" height="15"  uuid="07e3ff2a-3832-4b06-9275-cb1ee8e51cfe"/>
                                  <textFieldExpression><![CDATA[$F{Gender}]]></textFieldExpression>
                              </textField>
                              <textField>
                                  <reportElement x="200" y="3" width="121" height="15" uuid="07e3ff2a-3832-4b06-9275-cb1ee8e51cfe"/>
                                  <textFieldExpression><![CDATA[$F{Phone}]]></textFieldExpression>
                              </textField>
                          </jr:listContents>
                      </jr:list>
                  </componentElement>
              </band>
          </detail>
      </jasperReport>
    
  2. Create a method named generatePDFReport and call the jasper-report connector appropriate method, which will return the generated PDF Jasper Report.

    import java.io.*;
    import java.util.HashMap;
    import javax.servlet.http.HttpServletResponse;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.web.client.RestTemplate;
    
    
    import com.wavemaker.runtime.service.annotations.ExposeToClient;
    import com.wavemaker.runtime.service.annotations.HideFromClient;
    
    
    import com.wavemaker.runtime.file.model.DownloadResponse;
    import com.wavemaker.runtime.file.model.Downloadable;
    
    import com.wavemaker.connector.jasper.JasperConnector;
    import com.wavemaker.connector.jasper.JasperExportType;
    //import com.jasperreportconnector_integratio.jasperreportservice.model.*;
    
    
    @ExposeToClient
    public class JasperReportService {
    
        private static final Logger logger = LoggerFactory.getLogger(JasperReportService.class);
        
        @Autowired
        private JasperConnector jasperConnector;
        
        public Downloadable generatePDFReport() {
            String data = invokeService();
            
            logger.info("Calling connector to generate the jasperRepoet");
            ByteArrayOutputStream pdfReportStream = (ByteArrayOutputStream) jasperConnector.generateReport(JasperExportType.PDF, "jasperReport/restApi.jrxml", new HashMap<>(), data);
                                
            DownloadResponse downloadableResponse = new DownloadResponse(new ByteArrayInputStream(pdfReportStream.toByteArray()), "application/pdf", "jasper.pdf");
    
            downloadableResponse.setInline(false);
    
            return downloadableResponse;
        }
        
        // This method actually connects to the external web service
        private String invokeService() {
            String url = "https://randomuser.me/api?results=10&format=json";
            
            RestTemplate restTemplate = new RestTemplate();
            String response = restTemplate.getForObject(url, String.class);
            logger.info(" Rest response : " + response);
            return response;
        }    
        
    }
    
    note

    Here we can use various export types defined in JasperExportType class

    public enum JasperExportType {
        HTML, PDF, XLS, CSV, DOC
    }
    

Step 3: In the Main page drag and drop an Iframe onto the canvas.

  1. Drag and drop the iframe widget and set the Source Property from the properties panel for Iframe.
  2. Save and run the project – The PDF Report gets generated. You can download the PDF file.
  • PDF report for Employee data

  • PDF report for Rest API data

Last updated on 12/21/2022 by Ganesh Balagam
← Integrating Sample Jasper Report in WaveMaker ApplicationUpgrading an App from WaveMaker 9.x to WaveMaker 10.0 →
  • Step 1: Import the jasper-report-connector to project
  • Step 2: Create a Java Service
    • Example 1: Generating Jasper Report from a imported DataBase:
    • Example 2: Generating Jasper Report by consuming the API Data
  • Step 3: In the Main page drag and drop an Iframe onto the canvas.
WaveMaker
  • PRICING
  • PARTNERS
  • CUSTOMERS
  • ABOUT US
  • CONTACT US
Terms of Use | Copyright © 2013-2023 WaveMaker, Inc. All rights reserved.