Jump to content
We've recently updated our Privacy Statement, available here ×
  • How to use URL query string parameters within your query-based input control


    ghudson_1
    • Features: Input Controls Version: v4.7.1 Product: JasperReports® Server

    Issue:

    Http url query string parameters, like firstname & hobby in the following url, can be used in JasperReports Server reports, even as inputs to the query-based input controls:

    http://myserver.com/testpage.html?firstname=greg&hobby=fun


    Resolution:

    This example uses the foodmart sample database tables shipped with JasperReports Server.  This example was created in 4.7.1.

    Define the parameter for use within your JRXML:

    <parameter name="position_param" class="java.lang.String"/> 

    For testing, my input parameter is in my main report query:

    select * from employee where position_title = $P{position_param} limit 5

    Within the web UI of your report, in the "Controls and Resources" page create the first input control with these characteristics:

    Name is foo, single value, invisible or visible, text is the datatype.

    Use these characteristics for your second input control created in the "Controls and Resources" page:

    Name it position_param (name obviously has to match what we created in jrxml), singe select query, mandatory checkbox, and 

    In the query use:  select position_title from employee where position_title = $P{foo}.  Ensure position_title is returned in the values. 

    On the "Controls and Resources page ensure the "always prompt" is unchecked. 

    Execute your reports url with the query param &foo=President, for example, using a report name "urlparam" residing in your Public folder:

    http://localhost:8070/jasperserver-pro/flow.html?_flowId=viewReportFlow&standAlone=true&_flowId=viewReportFlow&ParentFolderUri=%2Fpublic&reportUnit=%2Fpublic%2Furlparam&foo=President

    Attached is a js-export zip which can be imported.  You'll need to ensure the datasource is correct and run as superuser.


    Ref. Case #00029184

     

    urlparameter.zip


    User Feedback

    Recommended Comments

    This is a stupid article. Everyone who has basic Jasper knowledge can do this. 

    Here is a challenge for you:  how can you resolve the issue if the URL has path variable instead of request parameter? I.E. if the URL is like this format, 
    - http://host:port/v1/clients/{clientId}/summary 

    (An example could be this: http://localhost:8080/v1/clients/189728/summary  )

    How can you solve this?

    Link to comment
    Share on other sites



    Guest
    This is now closed for further comments

×
×
  • Create New...