The inputControls Service

The reports service includes methods for reading and setting input controls. The rest_v2/reports/inputControls methods return an XML descriptor by default, but you can optionally specify the JSON format. The examples in this section use the JSON format.

This chapter includes the following sections:

Listing Input Control Structure
Listing Input Control Values
Setting Input Control Values

Listing Input Control Structure

The following method returns a description of the structure of the input controls for a given report.

Method

URL

GET

http://<host>:<port>/jasperserver[-pro]/rest_v2/reports/path/to/report/inputControls/

Options

accept: application/json

Return Value on Success

Typical Return Values on Failure

200 OK – The content is a JSON object that describes the input control structure. See example below.

404 Not Found – When the specified report URI is not found in the repository.

The body of the response contains the structure of the input controls for the report. This structure contains the information needed by your application to display the input controls to your users and allow them to make a selection. In particular, this includes any cascading structure as a set of dependencies between input controls. Each input control also has a type that indicates how the user should be allowed to make a choice:

bool

singleSelect

singleSelectRadio

multiSelectCheckbox

multiSelect

singleValue

singleValueText

singleValueNumber

singleValueDate

singleValueDatetime

singleValueTime

The following example shows a response in the JSON format:

{
"inputControl" : [ {
  "id":"Cascading_name_single_select",
  "label":"Cascading name single select",
  "mandatory":"true",
  "readOnly":"false",
  "type":"singleSelect",
  "uri":"repo:/reports/samples/Cascading_multi_select_report_files/Cascading_name_single_select",
  "visible":"true",
  "masterDependencies":{"controlId":["Country_multi_select","Cascading_state_multi_
                        select"]},
  "slaveDependencies":null,
  "validationRules": [{ ... }]
  "dataType": {
    "type": "number",
    "maxValue": "20",
    "strictMax": true,
    "minValue": "5",
    "strictMin": true
  }
  "state": {
    "uri": "/reports/samples/Cascading_multi_select_report_files/
            Cascading_name_single_select",
    "id": "Cascading_name_single_select",
    "value": null,
    "options": [{
      "selected": false,
      "label": "A & U Jaramillo Telecommunications, Inc",
      "value": "A & U Jaramillo Telecommunications, Inc"
      },      ...      ]}               }
  },
  ...
]}

The structure includes a set of validation rules for each input control. These rules indicate what type of validation your client should perform on input control values it receives from your users, and if the validation fails, the message to display. Depending on the type of the input control, the following validations are possible:

mandatoryValidationRule – This input is required and your client should ensure the user enters a value.
dateTimeFormatValidation – This input must have a data time format and your client should ensure the user enters a valid date and time.

The following sample shows the structure of these two possible validation rules.

  "validationRules": [{
    "mandatoryValidationRule" : {
      "errorMessage" : "This field is mandatory so you must enter data."
    },
    "dateTimeFormatValidationRule" : {
      "errorMessage" : "Specify a valid date value.",
      "format" : "yyyy-MM-dd"
    }
  }]

Listing Input Control Values

The following method returns a description of the possible values of all input controls for the report. Among these choices, it shows which ones are selected.

Method

URL

GET

http://<host>:<port>/jasperserver[-pro]/rest_v2/reports/path/to/report/inputControls/values/

Options

accept: application/json

Return Value on Success

Typical Return Values on Failure

200 OK – The content is a JSON object that describes the input control values and selection.

404 Not Found – When the specified report URI is not found in the repository.

The body of the response contains the structure of the input controls for the report. The following example shows a response in the JSON format:

{
  "inputControlState" : [ {
    "uri" : "/reports/samples/.../Country_multi_select",
    "value" : "",
    "options" : {
      "label" : "Canada",
      "selected" : "false",
      "value" : "Canada"
    }, {
      "label" : "Mexico",
      "selected" : "false",
      "value" : "Mexico"
    }, {
      "label" : "USA",
      "selected" : "true",
      "value" : "USA"
    } 
  },
  ...
  ]
}

If a selection-type input control has a null value, it is given as ~NULL~. If no selection is made, its value is given as ~NOTHING~.

Setting Input Control Values

The following method validates the input controls that you send, to ensure that they can be used in the next run of the report.

Method

URL

POST

http://<host>:<port>/jasperserver[-pro]/rest_v2/reports/path/to/report/inputControls/<ic1>;
<ic2>;.../values/

Content-Type

Content

application/json

A JSON object that lists your selected values. The value of every input control is given as an array of string values, even for single-select controls or multi-select controls with a single value. See also the example below:

{
  "boolean-input-control" : ["true"],
  "integer-input-control" : ["123456"],
  "single-select-input-control" : ["some value"],
  "multiple-select-input-control-1" : ["another value"],
  "multiple-select-input-control-2" : ["first", "second", "third"]
}

Options

accept: application/json

Return Value on Success

Typical Return Values on Failure

200 OK – The content is a JSON object that describes the new selection of input control values.

404 Not Found – When the specified report URI is not found in the repository.

Assuming the client receives the response given in Listing Input Control Values, it can send the following request body:

{
   "Country_multi_select":["Mexico"],
   "Cascading_state_multi_select":["Guerrero", "Sinaloa"]
}

When specifying the option for the JSON format, the server’s response is:

{
  "inputControlState" : [ {
    "uri" : "/reports/samples/.../Country_multi_select",
    "value" : "",
    "options" : {
      "label" : "Canada",
      "selected" : "false",
      "value" : "Canada"
    }, {
      "label" : "Mexico",
      "selected" : "true",
      "value" : "Mexico"
    }, {
      "label" : "USA",
      "selected" : "false",
      "value" : "USA"
    }
  },
  ...
  ]
}
Version: 
Feedback