Skip Headers

Oracle9i Reports Building Reports
Release 9.0

Part Number A92101-01
Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to next page

1
Building a Report with a Barcode

Reports Builder enables you to create any type of report that displays barcodes. By using the Oracle9i Reports barcode JavaBean, you can build reports for the Web or for paper that display a barcode to make tasks like tracking shipping orders and employee identification numbers easier. In Reports 6i, you had to use a barcode font to generate the barcode. In Oracle9i Reports Builder, the JavaBean automatically generates the barcode for you.

To learn more about the barcode JavaBean, visit the Oracle Technology Network (http://otn.oracle.com/products/reports/), then click Getting Started with Oracle9i Reports and click PL/SQL-Java Bridge in the navigation bar.

Example Scenario

You will build two reports in this section, one for paper and one for the Web. The paper report shows an invoice for a single customer who has ordered multiple items from a company. The barcode indicates the tracking information for the order.

To build either of these reports, you must first refer to Section 1.1, "Prerequisites for this example".

Table 1-1 Features Demonstrated in the Barcode Bean Example
Feature Location

Use the Java importer to add the barcode JavaBean for a paper report.

Section 1.2.1, "Import the Java classes into Reports Builder"

Use the Program Unit editor to create a PL/SQL package for a paper report.

Section 1.2.2, "Create a package to store your information"

Create a Before Report trigger to set up your barcode JavaBean for a paper report.

Section 1.2.3, "Create a Before Report trigger"

Use the Data Model view and toolbar to create a data model with a formula column for a paper report.

Section 1.2.4, "Create a data model with a formula column"

Create a simple JSP-based Web report.

Section 1.3.1, "Create a query in an existing HTML file"

Create formula columns to call the barcode data for your Web report.

Section 1.3.2, "Create three formula columns in your data model"

Edit the JSP code in the Web source view.

Section 1.3.3, "Initialize the barcode JavaBean and set its properties"

View your JSP-based Web report in a browser.

Section 1.3.4, "Run your report to the Web"

1.1 Prerequisites for this example

To build the examples in this manual, you must have the example files we've provided, as well as access to the sample schema that is shipped with the Oracle9i database.

1.1.1 Example files

If you haven't already done so, you can download the files you'll need to complete this example from the Oracle Technology network and install them on your machine.

To download and install the example files:

  1. Go to the Oracle Technology Network Web site (http://otn.oracle.com/product/reports/).

  2. Click Getting Started with Oracle9i Reports.

  3. Click Index, then find the "Building a Paper Report with a Barcode JavaBean" example and "Building a Web Report with a Barcode JavaBean" example. To complete this chapter, you need both sets of files. Note that this chapter covers how to build both a paper report and a Web report with a barcode bean.

  4. Download the files BarcodePaper.zip and BarCodeWeb.zip into a temporary directory on your machine (e.g., "d:\temp").

  5. Unzip the contents of the file, maintaining the directory structure, into an examples directory on your machine (e.g., d:\orawin90\examples).

    This zip file contains the following files:

    Table 1-2 Files necessary for building the barcode JavaBean sample reports
    File Description

    Examples\BarCodeBeanPaper\result\ShippingManifest.pdf

    The final PDF version of the paper report, containing the barcode.

    Examples\BarCodeBeanPaper\scripts\oraclebarcode.jar

    The barcode JavaBean.

    Examples\BarCodeBeanPaper\source\ShippingManifest.rdf

    The source file for the sample paper report. Running this RDF in Reports Builder will display the final result of your paper report in the Paper Design view.

    Examples\BarCodeBeanWeb\result\ShippingManifestWeb.jsp

    The final JSP version of the Web report, containing the barcode.

    Examples\BarCodeBeanWebresult\ShippingManifestWeb.rdf

    The final RDF version of the Web report, containing the barcode.

    Examples\BarCodeBeanWeb\result\assets

    The images that Oracle9i Reports generated when the JSP was run.

    Examples\BarCodeBeanWeb\scripts\SQL.txt

    The SQL for the query you need to enter.

    Examples\BarCodeBeanWeb\source\ShippingLabel.html

    The HTML page that you will use as a basis for the Web report.

    Examples\BarCodeBeanWeb\source\ShippingManifestWeb.rdf

    The source file for the sample Web report. Running this RDF in Reports Builder to the Web will display the final result of your Web report in your browser.

    Examples\BarCodeBeanWeb\source\assets\*

    The images and other files that your JSP-based Web report will require to display properly on the Web.

    Examples\BarCodeBeanWeb\source\assets\BLAFbeige_logo.gif

    The image you will use in your JSP-based Web report.

1.1.2 Access to the sample schema

If you don't know if you have access to the sample schema provided with the Oracle9i database, contact your database administrator. You should have access to the "Order Entry" portion of the schema to complete this example.

1.1.3 Update the REPORTS_CLASSPATH environment variable

Before you use a Reports JavaBean (for paper or the Web), you need to perform several steps. You first need to set up your environment to use the correct classpath for the bean. For a paper report, you must then use the Java Importer to import the JavaBean into Reports Builder. For a Web report, you must call the JavaBean from your JSP-based (JavaServer Page) report.

In this section, you will update the Reports class path with the location of the JavaBean. When you launch Reports Builder, it will use this new class path to recognize the location of the barcode bean.


Note:

You must follow the steps in this section before you can even run the finished report we've provided, called ShippingManifestPaper.rdf and ShippingManifestWeb.rdf.


  1. Find the class path:

    • In Windows, open the registry using regedit (you may want to export a backup before you modify your registry) and update the REPORTS_CLASSPATH environment variable.

    • On UNIX, update the REPORTS_CLASSPATH environment variable.

  2. Modify the class path to reflect the following:

    ORACLE_HOME/Examples/BarCodeBeanPaper/Scripts/oraclebarcode.jar;
    


    Note:

    ORACLE_HOME is where Reports Builder is installed (ex. d:\orawin90\) and Examples is where your examples are installed.


  3. Save the new environmental variable.

You are now ready to begin building your report.

1.2 Create a barcode report for paper

In this section, you will create a paper-based report that shows the invoice for a particular customer. This invoice will display the address of the customer, his order, and a barcode that represents the tracking number for the order. The company can scan this barcode to find out the status of the order.

Next, you will import the JavaBean, then create a barcode report for paper (Acrobat PDF). If you want to learn how to create a barcode JSP-based report for the Web, skip to Section 1.3.

1.2.1 Import the Java classes into Reports Builder

To create a paper report using the barcode JavaBean, you must first import two Java classes into Reports Builder. When you import these Java classes, Reports Builder automatically creates the packages you need to build the report.


Note:

You do not need to perform this task if you're creating a Web report, as you will write JSP that calls the JavaBean.


To import the Java classes:

  1. Launch Reports Builder.


    Note:

    You must launch Reports Builder now so that the new classpath is used.


  2. Close the Welcome dialog box by clicking Cancel.

  3. Choose Program > Import Java Classes...

  4. In the Import Classes field of the Import Java Classes dialog box, type oracle.apps.barcode.util.BarCodeConstants, then click Import.

  5. Once the packages have been created, import the second JavaBean: oracle.apps.barcode.BarCodeMaker.

  6. Click Close.

  7. In the Object Navigator, look under the report called "MODULE 1." Click the Program Units node. You'll notice that Reports Builder created two package specs and two package bodies named BARCODECONSTANTS and BARCODEMAKER.

1.2.2 Create a package to store your information

In this report, you want to create a package where the information will be stored.

To create a package for storing your information:

  1. In the Object Navigator, under your new report, click the Program Units node.

  2. Click the Create icon to add a program unit.

  3. In the New Program Unit dialog box, type globals.

  4. Select the Package Spec radio button, then click OK.

  5. Type the following code in the editor:

    PACKAGE globals IS
    
    bcobj ora_java.jobject;
    barcode_to_use varchar2(256);
    tempdir varchar2(100);
    directory_sep varchar2(2);
    
    END
    
    

    You can also copy and paste the code from the complete example (Examples\BarCodeBeanPaper\source\ShippingManifest.rdf). Open the RDF in the Object Navigator. Under the example name, open the Program Units node. You should see the "Globals" package body listed. Open this package, then copy and paste the code from this package into your new program unit.

  6. Click Compile to make sure there are no errors in your code.


    Note:

    If your code does not compile, make sure you've typed in exactly the code we've provided.


  7. Once the code is compiled, click Close.

  8. In the Object Navigator, select your report (e.g., "MODULE 1").

  9. Choose File > Save.

  10. Name the file shippingmanifest_<your initials>.rdf (e.g., shippingmanifest_vw) and make sure you save it to a new directory (e.g., "My Examples"), where your new files are stored.

  11. Click Save.

You have created a package that will contain the global information for your report.

1.2.3 Create a Before Report trigger

You can use the Before Report trigger to initialize specific tasks that will run before the report runs. Here, you will define the type of barcode you want to use in your report, as well as the temporary directory where your barcode images will be stored.

  1. In the Object Navigator, under SHIPPINGMANIFEST_<your initials>, click the Report Triggers node.

  2. Double-click BEFORE REPORT.

  3. Type the following code in the editor, between the existing text (indicated in bold):

    function BeforeReport return boolean is
    
    begin
    globals.barcode_to_use := BarCodeConstants.BAR_CODE_128;
    globals.bcobj := barcodemaker.new();
    
    return (TRUE);
    end;	
    
    You can change the value BarCodeConstants.BAR_CODE_128 to any other valid 
    value. To determine which values are valid, check the contents of the package 
    by opening the BarCodeConstants package spec in the Object Navigator, under 
    the Program Units node.
    
    


    Note:

    You can also copy and paste the code from the complete example (Examples\BarCodeBeanPaper\source\ShippingManifest.rdf). Open the RDF in the Object Navigator. Under the example name, open the Report Triggers node. You should see the "BEFORE REPORT TRIGGER" listed. Open this trigger, then copy and paste the code from the editor into your new function.


  4. Click Compile to make sure there aren't any errors.


    Note:

    If you have errors, make sure you've imported the necessary Java classes and that your code matches the code above. If you change the code, be sure to compile it again


  5. When the code is compiled, click Close.

  6. Save your report.

You have created a trigger that will set up the barcode type for you when you run the report.

1.2.4 Create a data model with a formula column

In this section, you will manually create the query that the report will use to retrieve data from the sample schema. You will also create a formula column that will communicate with the JavaBean to create the barcode, then return the file name of the generated image.

1.2.4.1 Create the query

  1. In the Object Navigator, under SHIPPINGMANIFEST_<your initials>, double-click Data Model to display the Data Model view for your report.

  2. In the tool palette, click the SQL Query icon, then click in the main area (canvas region) of the Data Model view.

  3. In the SQL Query Statement field, type (or paste) the following code:

    
    SELECT ALL CUSTOMERS_A1.CUST_FIRST_NAME, 
    
    CUSTOMERS_A1.CUSTOMER_ID, CUSTOMERS_A1.CUST_LAST_NAME,
    CUSTOMERS_A1.CUST_ADDRESS.STREET_ADDRESS,
    CUSTOMERS_A1.CUST_ADDRESS.POSTAL_CODE, 
    CUSTOMERS_A1.CUST_ADDRESS.CITY,
    CUSTOMERS_A1.CUST_ADDRESS.STATE_PROVINCE, 
    CUSTOMERS_A1.CUST_ADDRESS.COUNTRY_ID, ORDERS.ORDER_ID,
    ORDERS.ORDER_DATE, 
    ORDERS.ORDER_TOTAL, ORDER_ITEMS.LINE_ITEM_ID,
    PRODUCTS.PRODUCT_NAME, 
    ORDER_ITEMS.UNIT_PRICE, ORDER_ITEMS.QUANTITY,
    COUNTRIES.COUNTRY_NAME
    FROM CUSTOMERS CUSTOMERS_A1, ORDER_ITEMS, ORDERS,
    PRODUCTS, HR.COUNTRIES
    
    WHERE ((ORDER_ITEMS.ORDER_ID = ORDERS.ORDER_ID)
    
    AND (ORDERS.CUSTOMER_ID = CUSTOMERS_A1.CUSTOMER_ID)
    AND (ORDER_ITEMS.PRODUCT_ID = PRODUCTS.PRODUCT_ID)
    AND (CUSTOMERS_A1.CUST_ADDRESS.COUNTRY_ID =
    HR.COUNTRIES.COUNTRY_ID)) 
    AND ORDERS.ORDER_ID = :P_ORDER_ID
    
    ORDER BY order_ID, line_item_ID
    
    You can also copy and paste the code from the complete example 
    (Examples\BarCodeBeanPaper\source\ShippingManifest.rdf). Open 
    the RDF in the Object Navigator. Under the example name, double-click Data 
    Model to display the Data Model view. Double-click the query (entitled Q_1) to 
    display the SQL Query Statement field.
    
    
  4. Click OK.

    If you are not connected to a database that contains the sample schema we've provided, you must log in now. If you're not sure what your connection string is, contact your database administrator.

  5. When a message displays indicating that the bind parameter p_order_id was created, click OK.

  6. In the data model you just created, select all of the following columns at once by using your mouse and the Shift key, then drag them below the current query into a detail group:

    • LINE_ITEM_ID

    • PRODUCT_NAME

    • UNIT_PRICE

    • QUANTITY

    The resulting data model should look like this:

Figure 1-1 Data Model for the query

Text description of orbrbc_dmp.gif follows.

Text description of the illustration orbrbc_dmp.gif

1.2.4.2 Create the formula column

To create the formula column:

  1. In the data model for your report, click the Formula Column icon to create a formula column.

  2. Click in the master group (the main group that still contains most of the column names).

    The Property Inspector for the formula column (CF_1) displays.

  3. Under Column, next to the Datatype property, select Character from the drop-down list.

  4. Click the PL/SQL Formula property to display the editor for the formula column.

  5. Type the following code in the editor (existing text is in bold):

    function CF_1Formula return Char is
      myFilename varchar2(20);
      result varchar2(20);
      barcodeData VarChar2(50) := :customer_ID ||
    :order_ID;
    begin
      myFileName := srw.create_temporary_filename;
      barcodemaker.setBarWidthInch(globals.bcobj, 0.005);
      barcodemaker.setBaseCodeData(globals.bcobj,barcodeData);
      barcodemaker.setBarCodeType(globals.bcobj,globals.barcode_to_use);
      barcodemaker.setFullPath(globals.bcobj, myFileName);
      barcodemaker.renderBarCode(globals.bcobj);
      return(myfilename);
    end;
    
    

    You can also copy and paste the code from the complete example (Examples\BarCodeBeanPaper\source\ShippingManifest.rdf). Open the RDF in the Object Navigator. In the Data Model view, open the Property Inspector for the formula column called "CF_1." Click the PL/SQL Formula property to display the code for the formula column.

    
    
  6. Click Compile to make sure there aren't any errors.


    Note:

    If you have errors, make sure you've imported the necessary Java classes and that your code matches the code above. If you change the code, be sure to compile it again.


  7. When the code is compiled, click Close.

  8. In the Property Inspector, find the Read from File property and set it to Yes.

  9. Set the File Format property to Image.

  10. Save the report.

You have created the data model for your barcode report, which contains a formula column that retrieves the barcode information and displays the barcode image on your report.

Your data model and the PL/SQL for the formula column should look similar to this:

Figure 1-2 Data Model and Program Unit Editor for the Formula Column CF_1

Text description of orbrbc_fcp_sm.gif follows.

Text description of the illustration orbrbc_fcp_sm.gif

1.2.5 Create a layout for your report

Before you can run your report, you must create a layout.

To create a paper layout:

  1. Under your report's node in the Object Navigator, right-click Paper Layout, then choose Report Wizard from the pop-up menu.

  2. On the Report Type page, click Next to create both a Web and paper layout.

  3. On the Style page, select the Group Above radio button, then click Next.

  4. On the SQL page, click Next.

  5. On the Data page, click Next.

  6. On the Groups page, make sure the following fields display in the Group Fields column:

    • ORDER_ID

    • ORDER_DATE

    • CUSTOMER_ID

    • CUST_FIRST_NAME

    • CUST_LAST_NAME

    • STREET_ADDRESSS

    • POSTAL_CODE

    • COUNTRY_NAME

    • CITY

    • STATE_PROVINCE

    • COUNTRY_ID

    • ORDER_TOTAL

    • CF_1

  7. On the Fields page, click the double arrows to display all fields.

  8. On the Totals page, make sure no totals display, then click Finish.

You have completed the layout for your paper report. When the report runs, the Runtime Parameter Form displays. Next to P_ORDER_ID, type 2354.

Your report displays in the Paper Design view, and should look something like the following:

Figure 1-3 Paper Design view of the Barcode Paper Report

Text description of orbrbc_finp.gif follows.

Text description of the illustration orbrbc_finp.gif


Note:

If you aren't sure whether you produced the desired results, you can always open the file we provided, called ShippingManifest.pdf in Acrobat Reader. Or, you can run ShippingManifest.rdf to paper and the report will display in the Paper Design view.


1.3 Create a barcode report for the Web

The steps in this section show you how to build a Web report using JavaServer Pages (JSPs), that uses the barcode JavaBean you imported in Section 1.2.1, "Import the Java classes into Reports Builder". If you want to build a paper report with a barcode, see Section 1.2, "Create a barcode report for paper".

If you are not familiar with creating a JSP-based Web report and would like an introduction to building them, refer to the Oracle9i Reports Tutorial, located in the Getting Started with Oracle9i Reports Web site on the Oracle Technology Network (http://otn.oracle.com/reports/).

The report you will create in this section is the same as the one you created for paper. You will create a report that displays the invoice for a particular customer. This invoice will display the address of the customer, his order, and a barcode that represents the tracking number for the order. The company can scan this barcode to find out the status of the order.

You can run the final version of the JSP report we've provided to see what you'll build in these steps, but please note that you will need to update the location of the images in the source code (see Section 1.3.3.1, "Update the paths to the assets") before you can run the report to the Web.

If you're not familiar with creating a JSP-based Web report, refer to the Oracle9i Reports Tutorial to learn how to create a simple JSP-based Web report.


Note:

Before you begin this section, make sure you have all the necessary files, and that you've imported the Java classes, and set up the class path. See Section 1.1, "Prerequisites for this example" and Section 1.2.1, "Import the Java classes into Reports Builder".


1.3.1 Create a query in an existing HTML file

When you create a JSP-based Web report, you can use an existing HTML file as a template.

To create a query in an existing HTML file:

  1. In Reports Builder, open the file Examples\BarCodeBeanWeb\source\ShippingLabel.html.

    If you don't know how to open the file, follow these steps:

    1. In Reports Builder, choose File > Open.

    2. Navigate to your examples directory. This is the directory where you've downloaded the examples files we've provided.

    3. Find and open the file called ShippingLabel.html.

  2. In the Object Navigator, under SHIPPINGLABEL, double-click the Data Model node to display the Data Model view for the report.

  3. In the tool palette, click the SQL Query icon, then click in the main area (canvas region) of the Data Model view.

  4. In the SQL Query Statement field, type (or paste) the following code:

    
    SELECT ALL CUSTOMERS_A1.CUST_FIRST_NAME,
    
    CUSTOMERS_A1.CUSTOMER_ID, CUSTOMERS_A1.CUST_LAST_NAME,
    CUSTOMERS_A1.CUST_ADDRESS.STREET_ADDRESS,
    CUSTOMERS_A1.CUST_ADDRESS.POSTAL_CODE,
    CUSTOMERS_A1.CUST_ADDRESS.CITY,
    CUSTOMERS_A1.CUST_ADDRESS.STATE_PROVINCE,
    CUSTOMERS_A1.CUST_ADDRESS.COUNTRY_ID,
    ORDERS.ORDER_ID, ORDERS.ORDER_DATE, ORDERS.ORDER_TOTAL,
    COUNTRIES.COUNTRY_NAME FROM CUSTOMERS CUSTOMERS_A1, ORDERS,
    HR.COUNTRIES
    
    WHERE ((ORDERS.CUSTOMER_ID = CUSTOMERS_A1.CUSTOMER_ID)
    AND (CUSTOMERS_A1.CUST_ADDRESS.COUNTRY_ID = HR.COUNTRIES.COUNTRY_ID))
    AND ORDERS.ORDER_ID = :P_ORDER_ID ORDER BY order_ID 
    


    Note:

    You can also copy and paste the code from the file we've provided: Examples\BarCodeBeanWeb\scripts\SQL.txt.


  5. Click OK.

    If you are not connected to a database that contains the sample schema we've provided, you must log in now. If you're not sure what your connection string is, contact your database administrator.

  6. When a message displays indicating that the bind parameter was created, click OK.

  7. In the Data Model view, right-click the group and choose Property Inspector to display the properties for the group.

  8. In the Name field, delete the existing text and type G_SHIPMENT, then press Enter.

    Doing so renames the group "G_SHIPMENT."

  9. Close the Property Inspector.

  10. Your data model should look something like this:

Figure 1-4 Data Model for the JSP-based Web Report Query

Text description of orbrbc_dmw.gif follows.

Text description of the illustration orbrbc_dmw.gif

  • Save your report as ShippingLabel_<your initials>.jsp.

    Doing so creates the JSP-based Web source for this report.

    You have now created the query that will pull in the data for your report.

    1.3.2 Create three formula columns in your data model

    You will need to create three formula columns in your report to retrieve the tracking number for the order, the origin of the order, and the destination for the order.

    1.3.2.1 Create the TrackingNumber formula column

    To create the TrackingNumber formula column:
    1. In the Data Model view, click the Formula Column icon in the tool palette.

    2. Click in the group to create your first formula column, temporarily called CF_1.

    3. In the Property Inspector for CF_1, rename the column TrackingNumber.

    4. Next to the Datatype property, choose Character from the list.

    5. Next to the PL/SQL Formula property, click the field to display the code editor.

    6. Type the following code in the editor (existing text is in bold):

      
      function TrackingNumberFormula return char is
      begin
      
      return(:Customer_id||:Order_ID||:country_ID);
      
      end;
      
      You can also copy and paste the code from the complete example 
      (Examples\BarCodeBeanWeb\source\ShippingManifestWeb.rdf). Open the RDF in the 
      Object Navigator. Double-click the Data Model node to display the data model. 
      In the group, scroll down to find the "TrackingNumber" formula column, then 
      open the Property Inspector for the column. Click the field next to "PL/SQL 
      Formula" to display the code.
      
      
    7. Click Compile.


      Note:

      If your code does not compile, make sure you've typed in exactly the code we've provided.


    8. When the code is compiled, click Close.

      The new formula column, TrackingNumber, displays in the data model.

    1.3.2.2 Create the OriginScan formula column

    To create the OriginScan formula column:

    1. Create another formula column, temporarily called CF_1, in the G_SHIPMENT group.

    2. In the Property Inspector for CF_1, rename the column OriginScan.

    3. Choose the Character datatype.

    4. Next to the PL/SQL Formula property, click the field to display the code editor.

    5. Type the following code in the editor (existing text is in bold):

      
      function OriginScanFormula return char is
      begin
      
      return('34324-OH-US');
      
      end;
      
      You can also copy and paste the code from the complete example 
      (Examples\BarCodeBeanWeb\source\ShippingManifestWeb.rdf). 
      Open the RDF in the Object Navigator. Double-click the Data Model node to 
      display the data model. In the group, scroll down to find the "OriginScan" 
      formula column, then open the Property Inspector for the column. Click the 
      field next to "PL/SQL Formula" to display the code.
      
      
    6. Click Compile.


      Note:

      If your code does not compile, make sure you've typed in exactly the code we've provided.


    7. When the code is compiled, click Close.

      The new formula column, OriginScan, displays in the data model.

    1.3.2.3 Create the DestinationScan formula column

    To create the DestinationScan formula column:

    1. Create another formula column, temporarily called CF_1, in the G_SHIPMENT group.

    2. In the Property Inspector for CF_1, rename the column DestinationScan.

    3. Choose the Character datatype.

    4. Next to the PL/SQL Formula property, click the field to display the code editor.

    5. Type the following code in the editor (existing text is in bold):

      
      function DestinationScanFormula return char is
      begin
      
      return(:postal_code||'-'||:state_province||'-'||:country_ID);
      
      
      end;
      
      You can also copy and paste the code from the complete example 
      (Examples\BarCodeBeanWeb\source\ShippingManifestWeb.rdf). 
      Open the RDF in the Object Navigator. Double-click the Data Model node to 
      display the data model. In the group, scroll down to find the "DestinationScan" 
      formula column, then open the Property Inspector for the column. Click the 
      field next to "PL/SQL Formula" to display the code.
      
      
    6. Click Compile.


      Note:

      If your code does not compile, make sure you've typed in exactly the code we've provided.


    7. When the code is compiled, click Close.

      The new formula column, DestinationScan, displays in the data model.

    8. Save your report as a JSP.

    You have created the three formula columns that will hold the values for the tracking number, the origin, and the destination of the order. Your data model should look something like this:

    Figure 1-5 Data Model with the Three Formula Columns

    Text description of orbrbc_dmfc.gif follows.

    Text description of the illustration orbrbc_dmfc.gif

    1.3.3 Initialize the barcode JavaBean and set its properties

    To tell your JSP-based Web report to communicate with the JavaBean, you need to initialize it in the JSP. Unlike using the JavaBean with a paper report, you do not need to use the Java importer to import the Java classes.

    In this section, you will also learn how to set the properties for the bean so that the correct data is being used to produce the barcode.

    If you don't want to bother with typing the code in yourself, you can always open the source file (Examples/BarCodeWeb/source/ShippingManifestWeb.rdf) and copy the appropriate pieces of the Web source into your report.

    1.3.3.1 Update the paths to the assets

    To ensure that the JavaBean references the correct barcode images, you must update your report with the correct path.

    To update the paths:
    1. Open the Web source for your JSP-based Web report, called ShippingLabel_<your initials>.

      In the Data Model view of your report, click the Web Source icon.

    2. In the Web source, look for the text: Define Path information for your barcode images.

    3. Under this text, update the paths to make sure they point to the directories where your images will be generated (e.g., d://temp//docroot//images// and images//). Be sure to maintain the integrity of the paths we provide.


      Note:

      The directory where these files are located must be accessible by the Web server. This directory is typically located somewhere below the directory where you keep your JSPs.


    1.3.3.2 Initialize the JavaBean

    To initialize the JavaBean:

    1. In the Web source, look for the text: Initialize the JavaBeans.

    2. Under this text, type the following code:

       <jsp:useBean id="BC" scope="page" 
      class="oracle.apps.barcode.util.BarCodeConstants" />
       <jsp:useBean id="BM" scope="page" class="oracle.apps.barcode.BarCodeMaker" 
      />
      

    1.3.3.3 Set the barcode JavaBean properties

    To set the JavaBean properties:

    1. In the Web source, look for the text: Setting the barcode's properties.

    2. Under this text, type the following code:

       <jsp:setProperty name="BM" property="BarCodeType" value="<%= BC.BAR_CODE_
      128 %>" />
       <jsp:setProperty name="BM" property="BarWidthInch" value="0.01"/>
       <jsp:setProperty name="BM" property="Directory" value="<%= 
      BarcodePhysicalPath %>"/>
      
      

    1.3.3.4 Define the barcode variables

    To define the barcode variables:

    1. In the Web source, look for the text: Define variables to hold the data for the three barcodes.

    2. Under the text, type the following code:

       <%! private String BarCodeData1 = "12345-XX-XX"; %>
       <%! private String BarCodeData2 = "12345-XX-XX"; %>
       <%! private String BarCodeData3 = "12345-XX-XX"; %>
      
      

    1.3.3.5 Create a For Each loop

    To create a For Each loop:

    1. In the Web source, look for the text: Replace this with your RW:FOREACH open tag.

    2. Replace the line with the following code:

      <rw:foreach id="R_G_SHIPMENT" src="G_SHIPMENT>
      
      
      
    3. Look for the text: Replace this with your RW:FOREACH close tag.

    4. Replace the line with the following code:

      </rw:foreach>
      

    1.3.3.6 Code the formula columns to render the barcodes

    1. In the Web source, look for the text: **BARCODETrackingNumber**.

    2. Under the text, type the following code:

      <!-- Get the value of the TrackingNumber and assign it to the variable -->
      <rw:getValue id="BarCodeData1" src="TrackingNumber"/>
      <!-- Set the data for tbe barcode and the filename -->
      <jsp:setProperty name="BM" property="BaseCodeData" value="<%= BarCodeData1 
      %>"/>
      <jsp:setProperty name="BM" property="FileName" value="<%= BarCodeData1 %>"/>
      <!-- Render the barcode -->
      <% BM.renderBarCode(); %>
      <!-- View the image in the page -->
      <img src="assets/barcodes/<%= BarCodeData1 %>">
      
      

      The line beginning with "<!--" are comments. If you don't want comments in your code, you don't have to add these lines.

      
      
    3. In the Web source, look for the text: **BARCODEOriginScan**.

    4. Under the text, type the following code:

      <!-- Get the value of the OriginScan and assign it to the variable -->
      <rw:getValue id="BarCodeData2" src="OriginScan"/>
      <!-- Set the data for tbe barcode and the filename -->
      <jsp:setProperty name="BM" property="BaseCodeData" value="<%= BarCodeData2 
      %>"/>
      <jsp:setProperty name="BM" property="FileName" value="<%= BarCodeData2 %>"/>
      <!-- Render the barcode -->
      <% BM.renderBarCode(); %>
      <!-- View the image in the page -->
      <img src="assets/barcodes/<%= BarCodeData2 %>">
      
      

      The line beginning with "<!--" are comments. If you don't want comments in your code, you don't have to add these lines.

    5. In the Web source, look for the text: **BARCODEDestinationScan**.

    6. Under the text, type the following code:

      <!-- Get the value of the DestinationScan and assign it to the variable -->
      <rw:getValue id="BarCodeData3" src="DestinationScan"/>
      <!-- Set the data for tbe barcode and the filename -->
      <jsp:setProperty name="BM" property="BaseCodeData" value="<%= BarCodeData3 
      %>"/>
      <jsp:setProperty name="BM" property="FileName" value="<%= BarCodeData3 %>"/>
      <!-- Render the barcode -->
      <% BM.renderBarCode(); %>
      <!-- View the image in the page -->
      <img src="assets/barcodes/<%= BarCodeData3 %>">
      


      Note:

      the line beginning with "<!--" are comments. If you don't want comments in your code, you don't have to add these lines.


    7. Save your report as a JSP. If you're not sure whether you copied the code in correctly, check the Examples/result/ShippingManifestWeb.rdf we've provided.

    1.3.4 Run your report to the Web

    Since you've created a Web report, you must run this report to the Web to see your results.

    1. Make sure your report, ShippingManifestWeb_<your initials>, is selected in the Object Navigator.

    2. In the toolbar, click the Run Web Layout icon to run your report to a browser.

      Your report displays in your Web browser, and should look something like this:

    Figure 1-6 Snapshot of the Final JSP-based Web Report with Barcode

    Text description of orbrbc_webf.gif follows.

    Text description of the illustration orbrbc_webf.gif


    Note:

    If you aren't sure whether you produced the desired results, you can always open the file we provided in the results directory, called ShippingManifestWeb.html in your Web browser. Or, you can run ShippingManifestWeb.jsp to the Web, and the report will display in the your browser.


    1.4 Summary

    Congratulations! You have created a paper report and a JSP-based Web report that use the barcode JavaBean to generate barcode images.

    You now know how to:

    For more information on JSPs (JavaServer Pages), refer to the Oracle9i Reports Tutorial or the Reports Builder online help.


  • Go to previous page Go to next page
    Oracle
    Copyright © 2002 Oracle Corporation.

    All Rights Reserved.
    Go To Documentation Library
    Home
    Go To Product List
    Solution Area
    Go To Table Of Contents
    Contents
    Go To Index
    Index