BackPrevious Page Next PageNext

Creating UDOs

Objects and interfaces for creating UDOs

Example 1: Accessing a record for a UDO and registering the UDO with the report system

Example 2: Making a group based on a UDO

Objects and interfaces for creating UDOs

The following objects and interfaces are necessary for creating a UDO. Refer to the corresponding class or interface in the JReport Javadoc located at <install_root>\help\api.

Then to create a UDO manually with the objects and interfaces, follow the steps:

  1. Inherit from the class JROblectTemplate to create a template file.
  2. Inherit from the class JRVisiableResult or JRObjectResult to create a result file.
  3. Implement JRObjectResultCreator to create a result creator file.
  4. Implement interface JRObjectRender to create a result render file. If you want to display a UDO in the Design area, implement interface JRObjectEditor. If your UDO is a group level object, implement interface JRGroupListener.
  5. Modify the file udo.ini in <install_root>\lib by adding the following:
    Begin 
    name=MyDbField
    template=myudo.MyDbFld
    resultobject=myudo.MyDbFldRst
    resultcreator=myudo.MyDbFldCreator
    resultviewer=myudo.MyDbFldRender
    End
  6. Compile the Java files, add the classes to the ADDCLASSPATH variable of setenv.bat in <install_root>\bin.

    Note: If you want to use class files for the UDO which have been used in previous versions, you should re-compile the source files.

Example 1: Accessing a record for a UDO and registering the UDO with the report system

This example describes how to access a record for your UDO and how to register your UDO with the report system.

  1. A UDO needs to implement at least four classes from JReport. The four classes are for template, result, creator and render files respectively.
  2. Compile the Java files.

    To compile these four Java files, you should add report.jar and JREngine.jar with their path into the class path (make sure that the path of the file JREngine.jar is before that of the file report.jar). For example, use the following command:

    Javac -classpath "C:\JReport\Designer\lib\JRengine.jar;C:\JReport\Designer\lib\report.jar;C:\test "MyDbFld.java

    Here it is assumed that JReport Designer is installed to C:\JReport\Designer. The Java files for the example are in C:\test\myudo.

  3. Modify the udo.ini file in the <install_root>\lib directory by appending the four classes as follows:
    Begin
    name=MyDbField
    template=myudo.MyDbFld
    resultobject=myudo.MyDbFldRst
    resultcreator=myudo.MyDbFldCreator
    resultviewer=myudo.MyDbFldRender 
    End
  4. Edit setenv.bat in <install_root>\bin by appending the path of the four classes to the batch file's ADDCLASSPATH variable. Assume that the four classes are located in D:\test\myudo.

    set ADDCLASSPATH=%JAVAHOME%\lib\tools.jar;D:\test;

  5. Start JReport Designer.
  6. Click Insert > UDO. You will now find a new UDO object named MyDbFld in the drop-down list of the Insert UDO dialog.

Example 2: Making a group based on a UDO

This example describes how to make a group based on a UDO. This sample is similar to a summary field. This example includes the implementation of four classes and shares a class with Example 1.

  1. Create the template, result, creator and render files as follows:
  2. Compile the four Java files in the same way as Example 1.
  3. Modify udo.ini in <install_root>\lib\ by appending the four classes as follows:
    Begin
    name=MySumFld 
    template=myudo.MySumFld 
    resultobject=myudo.MySumFldRst 
    resultcreator=myudo.MySumFldCreator 
    resultviewer=myudo.MyDbFldRender
    End
  4. Edit setenv.bat in <install_root>\bin by appending the path of the four classes to the batch file's ADDCLASSPATH variable. Assume that the four classes are located in D:\test\myudo.

    set ADDCLASSPATH=%JAVAHOME%\lib\tools.jar;D:\test;

  5. Start JReport Designer.
  6. Click Insert > UDO. You will now find a new UDO object named MySumFld in the drop-down list of the Insert UDO dialog.

BackPrevious Page Next PageNext