Jump to content
We've recently updated our Privacy Statement, available here ×
  • Creating a template that display ad hoc filter inputs


    Scott Andersen
    • Features: Ad Hoc, Input Controls, JasperReports Server, Reports Version: v8.2 Product: JasperReports® Server

    The ad hoc report designer is a great tool to create a report. However, selected filter values are not displayed on the resulting report.  This can be resolved by either putting the ad hoc view on a dashboard (which gives you access to the selected parameters); however, this approach limits the formatting of those values. A better approach is to use an ad hoc template to display the input values in a formatted way.

    Here are the steps to reference the filter values in a template.

    1. Create an ad hoc report that has a filter on it.

    converted-image.png.2fda745c6d2eea845028539d9b95c320.png
     

    1. Create a template that displays the selected values from the input control. Instructions on creating an ad hoc template can be found in the Jaspersoft Studio User Guide, section 12.4.
      https://community.jaspersoft.com/documentation/jaspersoft-studio-user-guide-820/v820/publishing-report-template

     

    1. To reference the parameters from the ad hoc view you need to access the “REPORT_PARAMETERS_MAP” parameter. This java.util.Map object contains all the parameters selected within the ad hoc view. The key within the parameter map will be the identifier in the domain of the field being filtered, appended with a sequential value.  The first time a field is used as a filter it will be “_1”, the second “_2” and so forth.

      To get the identifier, you can either look at the domain:
      converted-image.png.674e4af6f4ae62c3dec1da722e8c2347.png

       or drop the ad hoc view onto a dashboard and mouse over the filter to get the field identifier. In the image below, it is “product_family_1”.

    converted-image.png.3301ffafa4460afee5fe0fa4ddf45b2b.png
    converted-image.png.d0876b99ab35213122f77486c5df93b4.png

     

    1. In the “Text” field expression on the template, reference the “REPORT_PARAMETERS_MAP” value as follows:

      CONCATENATE($P{REPORT_PARAMETERS_MAP}.get( "product_family_1" ).toString())

    This template can be used when creating a report from the ad hoc view.

    converted-image.png.7575a74dc00d30ecc64d4857994a07cf.png

    The example template is attached below.

     

     

    input_control_in_template.


    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...