There are two approaches that you can take to invoke JReport Desktop Viewer Bean. They are described as follows:
Note: As JReport Server now supports NLS in web application UI, you need to specify -Djreport.url.encoding=UTF-8
for the JVM running the Desktop Viewer Bean in order to make the Desktop Viewer Bean work properly.
In this approach, your Java application calls the Java bean JRDirectViewer and provides the following properties:
When the Java bean JRDirectViewer has been loaded, it will ask JReport Server to run a report and display a dialog on the window asking for report parameters to be inputted (if they are required by the report). This approach has the advantage of not requiring your Java application to provide report parameters. However, a dialog will be displayed on the window for you to enter parameter values.
Note: The catalog name and the report name must contain file extensions (such as .cat or .cls). The catalog name must be a full path name which is relative to the server's root directory in the resource tree, and it is recommended that the report name should also be a full path name. If you are accessing JReport Servlet, you must also set the servlet path. For example, JRDirectViewer.setFullPath("/jrserver").
For the catalog name and full path string, the first character must be '/', and the last character cannot be '/'.
The second approach to invoking the Desktop Viewer Bean consists of two passes. The first pass obtains information about the parameters required by the report, and the second pass submits these parameters. If your Java application already knows the required parameters, the first pass can be omitted. In this approach the Desktop Viewer Bean will not display any dialog on the window. Your Java application retains full control of the window and is responsible for submitting all the required report parameters.
Pass one
Your Java application calls the Java bean JRPrepareViewer with the following properties:
JRPrepareViewer returns a vector containing information about the report. The method getReportParams() should be called after calling JRPrepareViewer to obtain the vector. The size of the vector is equal to the number of the parameters required by the report, which can be obtained by calling the method size(). Each element in the vector contains the type of a parameter, which can be obtained using the method getType(). The possible parameter types are listed below:
Note: While using Desktop Viewer Bean in JReport Server, if you want to show the parameter dialog and modify the parameter value in this dialog, you can call the method:
setPopupParamDialog(true/false)
where, "true" means that the parameter dialog will be displayed.
Pass two
In the second pass your Java application prepares the parameters based on the information provided by the vector. It then calls Java bean JRRunViewer with the following properties:
Note: Parameters - The string contains the parameter values, separated by commas (','). If more than one parameter is required in the report, you can pass multiple parameters in the paramValues string. The ValuesString format is: paraName1=paraValues1, paraName2=paraValue2, where the paraName1 and paraName2 are the parameter names and paraValue1 and paraValue2 are the values. The comma is the separator character, and the equals sign separates the parameter name and parameter value. If the parameter name or parameter value contains the separator character - comma or equal sign, it requires an escape. We provide an escape operator \\. If the escape operator is placed before the separate operator, it is not treated as a separate operator. For example:
the value for param1 is aaa, aa
the value for param2 is bbbbc
the value for param3 is ccccc
the value for pa=ram1 (name) is aaa, aa (value)
the value for param2 is bbbbb
the value for param3 is ccccc
Note that you do not necessarily need to set the values for all the parameters. If you do not set a parameter value, JReport will use the default value.