# Oracle Business Intelligence Beans Sample

## Displaying Linked Views

### Overview

This `BIViewServlet` demonstrates how BI Beans thin beans can be used in a servlet application. This class inherits user login functionality from `BIServlet`. The sample displays linked graph and crosstab. The sample uses the LOV Container bean to enable virtualized paging control.

### 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. The following code initializes a crosstab, a graph and an LOV Container.

`DataSource data = getDefaultDataSource(request);
crosstab = new ThinCrosstab();
crosstab.setThinBeanName(CROSSTAB_NAME);
crosstab.setPagingControlVisible(true);
crosstab.setDataSource(data);
handler.registerThinBean(crosstab);
LOVContainer lovContainer = new LOVContainer();
lovContainer.setThinBeanName(LOV_CONTAINER_NAME);
lovContainer.addLOVListener(new LOVAdapter(biHttpSession));
handler.registerThinBean(lovContainer);
crosstab.setEventTarget(BIConstants.INIT_LOV_EVENT,
new EventTargetImpl(lovContainer.getThinBeanName(), null));
Presentation presentation = new Presentation(ViewTypeTool.GRAPH);
presentation.setThinBeanName(PRESENTATION_NAME);
ThinGraph graph = (ThinGraph)presentation.getView();
graph.setDataSource(data);
graph.setDrillingEnabled(true);
graph.setImageSize(new Dimension(400, 250));
handler.registerThinBean(presentation);
`

Because both graph and crosstab are given the same instance of the data source, they will behave as linked views.

The application delegates to the `ServletRequestHandler` for handling thin bean events like drilling, paging, and so on.

`ServletRequestHandler handler = biHttpSession.getServletRequestHandler ( );
ServletQueryParameterProvider provider = new ServletQueryParameterProvider ( request, response );
handler.handleEvent ( provider );`

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.
`FormBean rootNode = new FormBean ( FORM_NAME );
ThinCrosstab crosstab = (ThinCrosstab)handler.getThinBean(CROSSTAB_NAME);
CrosstabBean crosstabNode = new CrosstabBean();
crosstabNode.setCrosstab(crosstab);
rootNode.addIndexedChild(crosstabNode);
Presentation graph = (Presentation)handler.getThinBean(PRESENTATION_NAME);
if (graph != null)
rootNode.addIndexedChild(new PresentationBean(graph));`

There is special handling for the LOV Container bean. If the application event indicates that the LOV Container should be displayed, then a UIX component for the LOV Container is added to the form instead of a crosstab and table.

`` `LOVContainer lovContainer = (LOVContainer)handler.getThinBean(LOV_CONTAINER_NAME);
LOVContainerBean lovContainerBean = new LOVContainerBean(lovContainer);
rootNode.addIndexedChild(lovContainerBean);
`

The thin beans in the `FormBean` UIX component are rendered as follows:

`ServletRenderingContext renderingContext = new ServletRenderingContext( this, request, response, out );
rootNode.render ( renderingContext );`

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.