# Oracle Business Intelligence Beans Sample

## Creating a Multiple Page Application

### Overview

The `BIMultiplePageServlet` class demonstrates a multiple-page application. The current page is stored as application state. The application state can be placed onto the URLs/Forms that an application generates so that the application can re-establish its state from a request's URL.

After connecting to the OLAP Catalog and to the BI Beans Catalog, the first page (Open Report) displays the contents of the BI Beans Catalog. The views can be opened using the ExplorerDetail thin bean. The views are displayed on the second page (Analyze) of the application.

### Code Highlights

The following section provides a walkthrough and explanations of the code fragments.``

The `processRequest` method is called by the base class after a successful user login. The first step of the application is to initialize the thin beans on the current page. The following code initializes the thin beans on the Open Report page.

`ExplorerDetail explorerDetail = new ExplorerDetail ( );
explorerDetail.setThinBeanName ( EXPLORER_DETAIL_NAME );
explorerDetail.setBIContext ( biHttpSession.getMetadataManager ( ).getMDRoot ( ) );
explorerDetail.addExplorerListener ( new OpenDeleteListener ( biHttpSession ) );
handler.registerThinBean ( explorerDetail );`

The application adds a listener with the ExplorerDetail thin bean. The thin bean fires an event when an open or delete event occurs on the client. The servlet can open or delete a view using the information in the event.

For opening a view:

`Hashtable env = new Hashtable ( );
QueryManager queryManager = biHttpSession.getQueryManager ( );
if ( queryManager != null ) {
env.put ( Query.QUERY_MANAGER, queryManager );
}
biHttpSession.getMetadataManager ( ).getMDRoot ( ).lookup ( location, ( Persistable ) dataView, env );`

If the view was opened successfully, then the application can change the current page to be the Analyze page. When opening a view, the application should clean up previously opened views if they are no longer required.

For deleting a view:

`biHttpSession.getMetadataManager ( ).getMDRoot ( ).unbind ( location );`

The application can render the HTML using a combination of raw HTML and thin beans. For rendering HTML, the application can retrieve the `PrintWriter` from the `HttpResponse` object and use `println` statements to output HTML to the client.

`response.setContentType ( "text/html" );
PrintWriter out = response.getWriter ( );`

The thin beans are added to a `FormBean` UIX component. For example, to render the Open Report page.

`FormBean rootNode = new FormBean ( PAGE_OPEN_REPORT );
ExplorerDetail explorerDetail = ( ExplorerDetail ) handler.getThinBean ( EXPLORER_DETAIL_NAME );
if ( explorerDetail != null ) {
ExplorerDetailBean explorerDetailBean = new ExplorerDetailBean ( explorerDetail );
rootNode.addIndexedChild ( explorerDetailBean );
}
rootNode.addIndexedChild ( new FormValueBean ( CURRENT_PAGE_PARAM, PAGE_OPEN_REPORT ) );`

Note that the current page is added as a hidden value in the form.

While the code cleans up the `BIHttpSession` that is related to a client, the resources allocated by the servlet need to be cleaned up. This includes beans that the servlet allocates for the session. The `close` method (implemented by `QueryClient`) should be called to release resources that are related to the data source. The `cleanUp` method should be called on the `ThinGraph` to release Graph-related resources.

Copyright © 2004 Oracle Corporation. All Rights Reserved.