Search code examples
jasper-reportsjasperserver

Set the name of an input control in a jrxml file. Is it possible?


I'd like to set the name of an input control in the jrxml file where it is defined; is that possible?

I know how to set the name of the input control via the Repository Explorer in Jaspersoft Studio, and I know how to set the name of an input control via the Jaspersoft Server.

However, I'd like to set the name of an input control in the jrxml file so that it will be set automatically upon being published to the server. Is there a property to use, similar to the following:

<parameter name="status_date_minimum" class="java.sql.Date">
  <property name="some.property.key" vhalue="Minimum Status Date"/>
  <defaultValueExpression><![CDATA[java.sql.Date.valueOf(java.time.LocalDate.now().minusYears(10).withMonth(1).withDayOfMonth(1))]]></defaultValueExpression>
</parameter>

Solution

  • As noted by @Siddharth in comments and suggested to me by a co-worker, there is a way to specify the label for the control outside of the user interface.

    JasperReports Server associates each report with an XML file that it appears to create around the time it publishes your report to the server. The XML file contains, among other information, the labels for any input controls.

    For an example of the XML file, first publish your report to a location on JasperReports Server. For the purpose of this example, the report file name is report.jrxml and the location is path/to/your; JasperReports Server appears to publish your report to path/to/your/report/Main jrxml (per JasperSoft Studio Repository Explorer) or path/to/your/report (per JasperReports Server Web UI).

    Second, export your report from JasperReports Server (via the Web UI or via the command line); JasperReports Server will produce a zip file with the following content:

    /index.xml
    /resources/path/.folder.xml
    /resources/path/to/.folder.xml
    /resources/path/to/your/.folder.xml
    /resources/path/to/your/report.xml
    /resources/path/to/your/report_files/main_jrxml.data
    

    main_jrxml.data contains the data from report.jrxml; report.xml contains the labels for any input controls. The content of report.xml may be similar to the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <reportUnit exportedWithPermissions="true">
        <folder>/resources/path/to/your</folder>
        <name>report</name>
        <version>2</version>
        <label>report</label>
        <description></description>
        <creationDate>2018-03-21T18:12:41.759-04:00</creationDate>
        <updateDate>2018-03-21T18:48:35.602-04:00</updateDate>
        <mainReport>
            <localResource
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    exportedWithPermissions="false" dataFile="main_jrxml.data" xsi:type="fileResource">
                <folder>/resources/path/to/your/report_files</folder>
                <name>main_jrxml</name>
                <version>4</version>
                <label>Main jrxml</label>
                <creationDate>2018-03-21T18:12:41.759-04:00</creationDate>
                <updateDate>2018-03-21T18:48:35.410-04:00</updateDate>
                <fileType>jrxml</fileType>
            </localResource>
        </mainReport>
        <inputControl>
            <localResource
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    exportedWithPermissions="false" xsi:type="inputControl">
                <folder>/resources/path/to/your/report_files</folder>
                <name>status_date_minimum</name>
                <version>1</version>
                <label>status_date_minimum</label>
                <creationDate>2018-03-21T18:48:35.602-04:00</creationDate>
                <updateDate>2018-03-21T18:48:35.602-04:00</updateDate>
                <type>2</type>
                <mandatory>false</mandatory>
                <readOnly>false</readOnly>
                <visible>true</visible>
                <dataType>
                    <localResource exportedWithPermissions="false" xsi:type="dataType">
                        <folder>/resources/path/to/your/report_files/status_date_minimum_files</folder>
                        <name>myDatatype</name>
                        <version>0</version>
                        <label>myDatatype</label>
                        <creationDate>2018-03-21T18:48:35.602-04:00</creationDate>
                        <updateDate>2018-03-21T18:48:35.602-04:00</updateDate>
                        <type>3</type>
                        <strictMin>false</strictMin>
                        <strictMax>false</strictMax>
                    </localResource>
                </dataType>
            </localResource>
        </inputControl>
        <inputControl>
            <localResource
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    exportedWithPermissions="false" xsi:type="inputControl">
                <folder>/resources/path/to/your/report_files</folder>
                <name>status_date_maximum</name>
                <version>1</version>
                <label>status_date_maximum</label>
                <creationDate>2018-03-21T18:48:35.602-04:00</creationDate>
                <updateDate>2018-03-21T18:48:35.602-04:00</updateDate>
                <type>2</type>
                <mandatory>false</mandatory>
                <readOnly>false</readOnly>
                <visible>true</visible>
                <dataType>
                    <localResource exportedWithPermissions="false" xsi:type="dataType">
                        <folder>/resources/path/to/your/report_files/status_date_maximum_files</folder>
                        <name>myDatatype</name>
                        <version>0</version>
                        <label>myDatatype</label>
                        <creationDate>2018-03-21T18:48:35.602-04:00</creationDate>
                        <updateDate>2018-03-21T18:48:35.602-04:00</updateDate>
                        <type>3</type>
                        <strictMin>false</strictMin>
                        <strictMax>false</strictMax>
                    </localResource>
                </dataType>
            </localResource>
        </inputControl>
        <alwaysPromptControls>true</alwaysPromptControls>
        <controlsLayout>1</controlsLayout>
    </reportUnit>
    

    You may edit the content of the reportUnit/inputControl/localResource/label element to change the name of the label.

    Once edited, you may import the data into the JasperReports Server. If you import through the command line, I recommend importing the directory, not the zip file - it appears that the command line import is picky about the zip format. Also, if you import through the command line, you must restart the JasperReports Server before you may run your changed report.