BackPrevious Page Next PageNext

JReport Exit Functions

Exit function properties

Executive interfaces

Using the Exit functions

JReport has developed three Exit functions: After Init Parameter, After Run and Before Run. These functions enable you to develop an action to be called before, during and after the process of running a report. A status will then be returned. If the returned status is true, the JReport Engine will go on running. If false, the JReport Engine will stop at this point.

Exit function properties

Open a report in JReport Designer. In the Report Inspector, select the node that represents the report tab and you will find the three Exit function properties: After Init Parameter, After Run and Before Run.

Report Inspector panel

Reference: For API information, see JReport Javadoc jet.util package and jet.exception package in <install_root>\help\api.

Executive interfaces

Three interfaces are provided for you to implement the Exit functions:

jet.util.JURLExecutor

This interface provides the following method, which is used to get the status of the JReport Engine:

jet.util.JURLEngineExecutor

This interface provides the following method, which is used to get the status of the JReport Engine:

jet.util.EngineExecutor

This interface provides three methods:

Reference: For API information, see JURExecutor, JUREngineExecutor and EngineExecutor interfaces in the JReport Javadoc jet.util package located at <install_root>\help\api.

Using the Exit functions

Example 1: Using parameters in the Exit functions

In this example, we provide a simple application which will run at all the three times, Before Run, After Init Parameter, and After Run.

  1. Develop your Java files to implement the methods. In the example, copy the following code and save it as testa.java to C:\JReport\Designer\help (here it is assumed that you have installed your JReport Designer to the default directory).
    import java.io.*;
    import java.awt.*;
    import java.net.*;
    import jet.util.*;
    
    public class testa implements JURLExecuter
    {
    	public boolean exec(String[] params) 
    	{
    		System.out.println("testa : ");
    		for (int i = 0; i < params.length; i++) 
    		{
    			System.out.print("\"" + params[i] + "\",");
    		}
    		System.out.println();
    		return true;
    	}
    }
  2. Compile testa.java to generate the class file testa.class in C:\JReport\Designer\help.
  3. Modify the batch file setenv.bat in C:\JReport\Designer\bin by appending the path C:\JReport\Designer\help into the batch file's ADDCLASSPATH variable:

    set ADDCLASSPATH=%JAVAHOME%\lib\tools.jar;C:\JReport\Designer\help;

  4. Start JReport Designer, then open a report with parameter.
  5. In the Report Inspector, select the node that represents the report tab and specify the class and give parameters for the three functions, for example:

    Report Inspector panel

    JURL:/ - The standard format, and followed by the class name.
    testa
    - The class name in this example.
    aa;bb;cc
    and 123;234;345 - The string type parameters of the class, which are divided by semicolons.
    Param
    - A predefined JReport parameter used in the current report, which is introduced by the symbol @.

    As shown above, two types of Exit function parameters are supported, they are:

  6. Run the report, the report engine will call the class that you specified in the Report Inspector.

Example 2: Using formulas in the Exit functions

JReport allows you to use formulas in the Exit functions. To do this, you can use the Data Container Link function which can return value of any formula to a parameter. And using the parameter in the Exit functions, you will get the value of the formula in the Exit functions.

  1. Create a formula and insert it into a report. It should be put in the child data component.
  2. Create a parameter with the same data type of the formula, leaving other options blank, and then insert it into the parent data component.
  3. Right-click the parent data component and click Data Container Link on the shortcut menu.
  4. In the Data Container Link dialog, click the Return Value tab, add the formula in the Field in Child Data Container to the Return Value box, then click OK.

    Now, you have finished passing value of the formula to a parameter.

  5. Use this parameter in the Exit functions with the method described in Example 1, and then the final value of formula will be returned in the Exit functions.

Notes:

BackPrevious Page Next PageNext