Viewing: Adding Reports Directly to the Repository > Uploading the Main JRXML

Adding a Simple Report Unit to the Server

This section presents an example of uploading a JRXML to the server. The report only has two image resources. The example defines a custom query for the report unit.

To add the simple report unit to the server, you need access to the following sample data installed with the server:

   <js-install>/samples/reports/AllAccounts.jrxml

   <js-install>/samples/images/logo.jpg files

Uploading the Main JRXML

If you want to validate the JRXML before uploading it, use iReport. The server doesn’t validate the JRXML when you upload it.

This procedure shows you how to set up a name for the report in the repository and upload the main JRXML file that references all other elements.

To upload the main JRXML for the simple report example:

1.     Log into the server as administrator and select View  Repository.

 

If you log in as a user, you can upload a report unit to the server, but this example requires an administrator login to access the image resources.

2.     Locate the folder where you want to add the report.

For example, go to Organization  Reports  Samples.

3.     Right-click the Samples folder and select Add Resource  JasperReport from the context menu.

 

Add Resource only appears on the context menu if your user account has write permission to the folder.

The Set Up the Report page of the JasperReport wizard appears.

4.     In Naming, enter the name and description of the new report, and accept the Resource ID generated as you type the name:

    Name

Display name of the report: New Simple Report

    Resource ID

Permanent designation of the report object in the repository: New_Simple_Report

    Description

Optional description displayed in the repository: This is a simple example

5.     Select Upload a Local File and Browse to <js-install>samples/reports/AllAccounts.jrxml.

 

You can upload a new JRXML or select a JRXML from the repository.

See "Required Set Up Values" shows the Set Up the Report page.

Required Set Up Values

6.     Click Controls & Resources.

The server uploads the main JRXML file. The Controls & Resources page reappears with a message to locate suggested resources.

 

Suggested Resources in the Resources List

The suggested resources are missing resources that the server needs to validate and run the report. In this example, suggested resources are the hyperlinked names of images:

    Logolink

    AllAccounts_Res2

Next, upload the suggested file resources.

Uploading Suggested File Resources

A JRXML file doesn’t embed resources, such as images. When the server uploads the JRXML, it tries to detect and list missing resources, as shown in See "Suggested Resources in the Resources List". You need to take one of the following actions:

   Upload resources that the report needs.

   Select a resource from the repository to the report.

If the Controls & Resources page doesn’t list any suggested file resources, perhaps the report doesn’t reference any. Often, the server can’t detect all of the referenced resources, as discussed in section Uploading Undetected File Resources.

To upload suggested file resources for the simple report example:

1.     Click Add Now in the same row as the suggested resource. For example, click Add Now for LogoLink.

The Locate File Resource page appears.

2.     Choose Select a resource from the Repository, and Browse to an image file. For example, Browse to Images/JR Logo.

 

Any image file works.

3.     Click Select.

The path to the image appears in the wizard.

4.     Click Next.

The Add a Report Resource page appears:

 

Properties of a Resource

The properties include the LogoLink name, resource ID, and description. These properties don’t redefine the properties of the JRLogo file in the repository.

5.     Click Next to accept the default naming of the file resource.

The Controls & Resources page appears again, showing that the LogoLink resource was added.

6.     On Controls and Resources, click Add Now in the AllAccounts_Res2 row.

The Locate File Resource page appears again.

7.     Select Upload a Local File, and Browse to <js-install>/samples/images/logo.jpg.

8.     Open logo.jpg, and click Next.

The server uploads the file.

The Add a Report Resource page appears, showing the properties of the file resource.

The properties include the AllAccounts_Res2 name, resource ID, and description.

9.     Click Next to accept the default naming of the file resource.

The Controls & Resources page reappears, showing the addition of both resources referenced in the main JRXML.

10.     Click Data Source and define a data source as described in the next section.

Referencing Styles

You can apply a style to your report by referencing a property sheet, created in iReport, that contains information on a style.

To do this, you will need to edit the Styles.jrxml file and change the <templates> statement.

To reference styles from an external property sheet:

1.     Locate and open the Styles.jrxml file.

2.     In the JRXML file, declare <template>"repo:styles"</template> (do not include the .jrtx extension).

3.     Save the JRXML file.

4.     Log into the sever as an administrator, and select View > Repository.

5.     Expand the Organization > Reports folder.

6.     Right-click the Samples folder and select Add Resource > JasperReport to open the Add JasperReport wizard.

7.     On the Set Up page, enter the required information.

8.     Select Upload a Local File and click Browse...

9.     Locate Styles.jrxml, and click Open.

10.     Click Submit.

11.     Copy the base_styles.jrtx file from the directory:

<jrs-install>\ireport\demo\samples\templates\reports

and place into the C:\ directory.

12.     Edit the styles.jrtx file and add C:\\ before base_styles.jrtx.

13.     Back on the server, select View > Repository, then expand the Organization folder.

14.     Right-click Images, and select Add Resource > File > Style Template.

15.     Under Path to File,click Browse... then locate the style.jrtx file.

16.     Enter a Name (Styles) and click Submit.

17.     In the repository, open the Reports > Styles folder, then right click on Styles report and select Edit.

18.     Click Control & Resources, then click the Add Resource... link.

19.     Select Select a resource from the Repository radio button, Browse...

20.     Locate Organization > Images > Styles, and click Select.

21.     Click Next button

22.     On the Add a Report Resource screen, enter Name: Styles, then click Next.

23.     Click Submit

Defining the Data Source

Data sources belong to the report engine, JasperReports Server, and are not defined in the main JRXML. The JRXML does not retain any data source defined in iReport when you add the JRXML to the server. You need to define a data source in the server that the report unit can use. From the Data Source page, select a data source in the repository or create a new data source on-the-fly. The data source can be different from the database configured for JasperReports Server if the application server can find its driver. For example, in a default installation of JasperReports Server, Tomcat looks for data source drivers in <js‑install>/apache-tomcat/lib. Put a copy of the driver in this location.

To define the data source for the simple report example:

1.     In the JasperReport wizard, click Data Source.

The Link a Data Source to the Report page presents these choices:

    Do not link a data source – Select or define the data source at a later time. You see an error if you run the report in this state.

    Click here to create a new data source – Define a new data source that is only available to your report.

    Select data source from repository – Select an existing data source from the repository.

2.     Choose Select data source from the Repository and Browse to /Data Sources/JServer JNDI Data Source. Click Select. The path to the data source appears.

 

Data Source Page

3.     Click Query to define the Query as described in the next section.

Defining the Query

The query in the report unit determines the data that the server retrieves from a data source. You can use an existing query or define a new one. You can create multiple reports that look the same but contain different data by defining different queries for the same JRXML file. The simple report example defines a custom query that displays accounts from a single country.

To define a custom query for the simple report example:

1.     In the JasperReport wizard, click Query.

The Locate Query page presents these choices:

    Do not link a Query – Uses the query, if there is one, defined within the main JRXML. If the main JRXML doesn’t have a query, you can’t run the report.

    Click here to create a new Query – Guides you through defining a new query, only available to your report.

    Select a Query from the Repository – Selects an existing query from the repository.

The AllAccounts.jrxml file uploaded in section Uploading the Main JRXML already contains a query. This example overrides the existing query by defining a new one.

2.     On the Query page, select the Click here to create a new Query option:

 

Query Page

3.     Click the link, Click here to create a new Query.

The Name the Query page appears where you can enter the name, resource ID, and description of the query. This query and its properties are visible only within the report unit.

4.     In this example, the query must retrieve only Canadian accounts. Enter the following values:

    Name – CanadaAccounts

    Resource ID – CanadaAccounts

    Description – Query for New Simple Report in User Guide

 

Name the Query Page

5.     Click Next.

The Link a Data Source to the Query page appears.

The Link a Data Source to the Query page appears. You can select a query from the repository, define a new one, or select not to link a data source.

6.     Select Do not link a data source to use the data source you selected in section You can apply a style to your report by referencing a property sheet, created in iReport, that contains information on a style..

7.     Click Next. The Define the Query page appears.

8.     Select SQL in the Query Language drop-down and enter the following Query String to retrieve only Canadian accounts:

SELECT * FROM accounts WHERE billing_address_country = ‘Canada’ ORDER BY billing_address_city

 

Definition of a Query

9.     Click Save to save the query. The Customization page appears. No customization is required.

10.     Click Submit to submit the new report unit to the repository.

Saving the New Report Unit

To submit a new report unit to the repository, click Submit on any page of the JasperReport wizard, from the Set Up page to the Customization page. You don’t have to set options on pages, such as Customization, you do not need. When you click Submit, the server validates the report unit. After clicking Submit, a message appears at the top of the repository page, indicating that the report was successfully saved. The report appears in the repository with the description you entered on the Set Up page. To run the report and view the output, click its name, New Simple Report.

 

New Simple Report Added to the Repository

Output of the New Simple Report shows the output, only Canadian accounts.

 

Output of the New Simple Report

In the Report Viewer, click to go to the end of the report. The logo images that you added as file resources appear.