8. Adding "Print" Functionality

Exercise Objectives

The objective of this session is to add a "Print" feature to the simple browsing application.

Exercise Description

Users may want to print the content of a presentation. You can add this functionality to the simple application easily by using predefined, custom BI Beans JSP tags.

Exercise Tasks

Create a "Printer Friendly" Page

BI Beans includes JSP tags that let you create a presentation page that is printer-friendly (that is, the presentation is formatted to print entirely on a page). Next, you will create this "Printer Friendly" page.

To create a new JSP

  1. Based on the directions in the Creating a Simple BI JSP Application exercise, create a new empty page for your JSP application. Use printerFriendlyJSP.jsp as the filename.
  2. Add a BIThinSession JSP tag with id app and the same connection configuration file /Project1BIConfig1.xml.
To open the PrinterFriendlyView tag wizard

  1. In the Code Editor, position the cursor on the line below the <%-- Insert your Business Intelligence tags here --%> comment.
  2. In the Component Palette pane, under Business Intelligence Tags, choose the PrinterFriendlyView icon.
To use the PrinterFriendly tag wizard

In the PrinterFriendlyView wizard, you can define the attribute values for the PrinterFriendlyView tag.

  1. In the id box, enter printerFriendly.
  2. Do not enter values in the remaining attributes.
  3. Choose Finish to create the tag.
To review the generated PrinterFriendly tag code

In the Code Editor, you can see the code that was generated for the PrinterFriendly tag. The following code creates the PrinterFriendly tag:

<orabi:PrinterFriendlyView id="printerFriendly" />

The following code displays the presentation in printer-friendly format:

<orabi:Render targetId="printerFriendly" parentForm="BIForm" />

From the File menu, choose Save All to save the JSP application.


Create the "Print Options" Page

You want to provide users with the ability to specify printing options before generating the printer-friendly page. Now, you will create a page that contains these printing options.

To create a new JSP

  1. Based on the directions in the Creating a Simple BI JSP Application exercise, create a new empty page for your JSP application. Use printJSP.jsp as the filename.
  2. Add a BIThinSession JSP tag with id app and the same connection configuration file /Project1BIConfig1.xml.
To open the PrintOptions tag wizard

  1. In the Code Editor, position the cursor on the line below the <%-- Insert your Business Intelligence tags here --%> comment.
  2. In the Component Palette pane, under Business Intelligence Tags, choose the PrintOptions icon.
To review the generated PrintOptions tag code

In the PrintOptions wizard, you can define the attribute values for the PrintOptions tag.

  1. In the id box, enter print.
  2. In the applyPage box, enter printerFriendlyJSP.jsp. This attribute identifies the "Printer Friendly" Page to use.
  3. In the printerFriendlyViewId box, select printerFriendly.
  4. Do not enter values in the remaining attributes.
  5. Choose Finish to create the tag.

In the Code Editor, you can see the code that was generated for the PrintOptions tag. The following code creates the PrintOptions tag:

<orabi:PrintOptions id="print" applyPage="printerFriendlyJSP.jsp" printerFriendlyViewId="printerFriendly" />

The following code displays the "Print" dialog:

<orabi:Render targetId="print" parentForm="BIForm" />

To create the Apply button for "Print"

  1. In the Code Editor, position the cursor above the line that contains the <%-- The InsertHiddenFields tag adds state fields to the parent form tag --%> comment.
  2. In the Component Palette pane, under Business Intelligence Tags, choose the ApplyButton icon.
  3. In the ApplyButton wizard, you can define the attribute values for the ApplyButton tag.
  4. Accept the default for the id (printJSP_ApplyButton1).
  5. In the dialogId box, select print.
  6. Do not enter values in the remaining attributes.
  7. Choose Finish to create the tag.

In the Code Editor, you can see the code that was generated for the ApplyButton tag. The following code creates an apply button for printing:

<orabi:ApplyButton id="printJSP_ApplyButton1" dialogId="print" />

The following code displays the apply button:

<orabi:Render targetId="printJSP_ApplyButton1" parentForm="BIForm" />

To create the Cancel button for "Print"

  1. In the Code Editor, position the cursor before the <%-- The InsertHiddenFields tag adds state fields to the parent form tag --%> comment. Press Enter to move the comment to the next line.
  2. In the Component Palette pane, under Business Intelligence Tags, choose the CancelButton icon.
  3. In the CancelButton wizard, you can define the attribute values for the CancelButton tag.
  4. Accept the default for the id (printJSP_CancelButton1).
  5. In the dialogId box, select print.
  6. Do not enter values in the remaining attributes.
  7. Choose Finish to create the tag.

In the Code Editor, you can see the code that was generated for the CancelButton. The following code creates an apply button for canceling:

<orabi:CancelButton id="printJSP_CancelButton1" dialogId="print" />

The following code displays the cancel button:

<orabi:Render targetId="printJSP_CancelButton1" parentForm="BIForm" />

From the File menu, choose Save All to save the JSP application.


Add "Print" button to the presentation viewer page

Finally, we need to add a "Print" button to the viewer page so that users can access the "Print Options" page to print the presentation.

To open the DialogLink tag wizard

  1. In the System-Navigator pane, right-click viewerJsp.jsp and choose Code Editor from the popup menu to open the Code Editor.
  2. In the Code Editor, position the cursor above the line that contains the <%-- The InsertHiddenFields tag adds state fields to the parent form tag --%> comment.
  3. In the Component Palette pane, under Business Intelligence Tags, choose the DialogLink icon.
To use the DialogLink tag wizard

In the DialogLink wizard, you can define the attribute values for the DialogLink tag.

  1. In the id box, enter printDialogLink.
  2. In the presentationId box, select viewer.
  3. In the targetPage box, select printJSP.jsp.
  4. In the targetToolId box, select print.
  5. In the text box, enter Print.
  6. Do not enter values in the remaining attributes.
  7. Choose Finish to create the tag.
To review the generated DialogLink tag code

In the Code Editor, you can see the code that was generated for the DialogLink tag. The following code creates a button for linking to the "Print" page:

<orabi:DialogLink id="printDialogLink" presentationId="viewer" targetPage="printJSP.jsp" targetToolId="print" text="Print" />

The following code displays the linking button:

<orabi:Render targetId="printDialogLink" parentForm="BIForm" />

From the File menu, choose Save All to save the JSP application.


Run the application

You have created a simple application that allows users to print a presentation.

  1. In the System-Navigator pane, right-click viewerJSP.jsp and choose Run viewerJSP.jsp.
  2. On the crosstab view page, choose Print.
  3. On the "Print" page, select the desired print options and choose Print.
  4. The browser refreshes and presentation is displayed. With the printer-friendly format of the graph in the browser, from the browser File menu, choose Print to print the presentation.
  5. Return to JDeveloper and, from the File menu, choose Terminate then Embedded OC4J Server to stop the application.

Exercise Summary

You added the "Print" feature to a simple application easily without writing a single line of code.

7. Adding "Export" Functionality | Overview | 9. Deploying a JSP Application