Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6565071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:02:50+00:00 2026-05-25T14:02:50+00:00

I have to generate reports based on various parameters which would be provided dynamically.

  • 0

I have to generate reports based on various parameters which would be provided dynamically. In certain contexts, the parameters may be null.
For example, from the table Person with id, name, age, sex and maritalStatus as fields, I would have to generate reports on married male persons of age 30. Some other times, it may be required to get married female without considering age. If I use the same jasper for both these cases, the age constraint will be null in second case. Is there any way to manage this condition?

Also, is it possible to dynamically specify which all fields should be produced in the report?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:02:51+00:00Added an answer on May 25, 2026 at 2:02 pm

    The sample of using the JasperReport API for generating report dynamically:

        //JasperDesign
        JasperDesign jasperDesign = new JasperDesign();
        jasperDesign.setName("The dynamically generated report");
        jasperDesign.setPageWidth(595);
        jasperDesign.setPageHeight(842);
        jasperDesign.setColumnWidth(515);
        jasperDesign.setColumnSpacing(0);
        jasperDesign.setLeftMargin(40);
        jasperDesign.setRightMargin(40);
        jasperDesign.setTopMargin(50);
        jasperDesign.setBottomMargin(50);
    
        //Query
        JRDesignQuery query = new JRDesignQuery();
        query.setText("SELECT * FROM Address $P!{OrderByClause}");
        jasperDesign.setQuery(query);
    
        //Fields
        JRDesignField field = new JRDesignField();
        field.setName("Id");
        field.setValueClass(java.lang.Integer.class);
        jasperDesign.addField(field);
    
        field = new JRDesignField();
        field.setName("FirstName");
        field.setValueClass(java.lang.String.class);
        jasperDesign.addField(field);
    
        field = new JRDesignField();
        field.setName("LastName");
        field.setValueClass(java.lang.String.class);
        jasperDesign.addField(field);
    
        //some code
    
        //Detail
        band = new JRDesignBand();
        band.setHeight(40);
    
        JRDesignStaticText staticText = new JRDesignStaticText();
        staticText.setX(0);
        staticText.setY(0);
        staticText.setWidth(60);
        staticText.setHeight(20);
        staticText.setMode(ModeEnum.OPAQUE);
        staticText.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
        staticText.setStyle(boldStyle);
        staticText.setText("ID: ");
        staticText.getLineBox().getLeftPen().setLineWidth(1);
        staticText.getLineBox().getTopPen().setLineWidth(1);
        staticText.getLineBox().setLeftPadding(10);
        band.addElement(staticText);
    
        textField = new JRDesignTextField();
        textField.setX(60);
        textField.setY(0);
        textField.setWidth(200);
        textField.setHeight(20);
        textField.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
        textField.setStyle(normalStyle);
        expression = new JRDesignExpression();
        expression.setValueClass(java.lang.Integer.class);
        expression.setText("$F{Id}");
        textField.setExpression(expression);
        textField.getLineBox().getTopPen().setLineWidth(1);
        textField.getLineBox().getRightPen().setLineWidth(1);
        textField.getLineBox().setLeftPadding(10);
        band.addElement(textField);
    
        staticText = new JRDesignStaticText();
        staticText.setX(0);
        staticText.setY(20);
        staticText.setWidth(60);
        staticText.setHeight(20);
        staticText.setMode(ModeEnum.OPAQUE);
        staticText.setHorizontalAlignment(HorizontalAlignEnum.LEFT);
        staticText.setStyle(boldStyle);
        staticText.setText("Name: ");
        staticText.getLineBox().getLeftPen().setLineWidth(1);
        staticText.getLineBox().getBottomPen().setLineWidth(1);
        staticText.getLineBox().setLeftPadding(10);
        band.addElement(staticText);
    
        textField = new JRDesignTextField();
        textField.setStretchWithOverflow(true);
        textField.setX(60);
        textField.setY(20);
        textField.setWidth(200);
        textField.setHeight(20);
        textField.setPositionType(PositionTypeEnum.FLOAT);
        textField.setStyle(normalStyle);
        expression = new JRDesignExpression();
        expression.setValueClass(java.lang.String.class);
        expression.setText("$F{FirstName} + \" \" + $F{LastName}");
        textField.setExpression(expression);
        textField.getLineBox().getRightPen().setLineWidth(1);
        textField.getLineBox().getBottomPen().setLineWidth(1);
        textField.getLineBox().setLeftPadding(10);
        band.addElement(textField);
    
        ((JRDesignSection) jasperDesign.getDetailSection()).addBand(band);
    

    You can find more samples in %JasperReportsFolder%/demo/samples folder from the JasperReports distribution package.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page which gives user to generate report based on different filters
I am working on a simple standalone desktop application which would generate report based
I would like to generate report from my php which now I have only
I'm using nose and coverage to generate coverage reports. I only have one package
Background: we have an application that generates reports from HTML (that may or may
I have a project where I would like to generate a report export in
I'm currently developing a program that will generate reports based upon lead data. My
I'm using Active Reports within my VB program to generate a report based on
I have an application which needs to generate a report. However, I do not
Problem: When doing reports, I have to manually export like 50 reports based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.