The BIStateServlet demonstrates state handling. The state of an application includes state strings that represent the state of the thin beans in the application and state strings representing application state. The state strings can be placed onto the URLs/Forms that an application generates, so that the application can re-establish the thin-bean's state from a request's URL. This placing of an application's state onto the URL enables an application to support re-establishing application state from a bookmark.
If you have not already done so, you must perform several installation
and configuration tasks, then open the workspace servlet\Servlet.jws
under the samples
directory within JDeveloper. All the necessary
files for this sample can be found in the state_handling.jpr
project
under the Servlet.jws
workspace.
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 thin bean.
ThinCrosstab crosstab = new ThinCrosstab ( );
crosstab.setThinBeanName ( CROSSTAB_NAME );
crosstab.setPagingControlVisible ( true );
crosstab.setDataSource ( dataSource );
handler.registerThinBean ( crosstab );
Similar to the registration of the crosstab, the datasource for the crosstab is registered with the request handler.
if ( dataSource instanceof ThinBean ) {
ThinBean dataSourceThinBean = ( ThinBean ) dataSource;
dataSourceThinBean.setThinBeanName ( DATASOURCE_NAME );
handler.registerThinBean ( dataSourceThinBean );
}
Establish the base state from which state changes that are included in the state string are tracked. This call clears the thin beans current state string.
crosstab.setBaseState ( );
if ( dataSource instanceof ThinBean ) {
( ( ThinBean ) dataSource ).setBaseState ( );
}
The application delegates to the ServletRequestHandler for handling thin-bean events.
ServletRequestHandler handler = biHttpSession.getServletRequestHandler
( );
ServletQueryParameterProvider provider = new ServletQueryParameterProvider
( request, response );
handler.handleRequest ( 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
);
if ( crosstab != null ) {
CrosstabBean crosstabBean = new CrosstabBean ( crosstab );
rootNode.addIndexedChild ( crosstab );
}
The application can call the getState method on the thin bean to retrieve the state string for the bean. The setState method on the thin bean allows the application to set the state string for the bean.
The state strings of all the thin beans registered with the ServletRequestHandler are added to the FormBean.
ServletRequestHandler handler = biHttpSession.getServletRequestHandler
( );
Dictionary stateStrings = handler.getState ( provider.getURLEncoder (
) );
The thin beans in a FormBean UIX component are rendered as follows:
ServletRenderingContext renderingContext = new ServletRenderingContext(
this, request, response, out );
renderingContext.setConfiguration ( BI_CONFIGURATION_KEY );
rootNode.render ( renderingContext );
While cleaning up the BIHttpSession related to a client, the resources allocated by the Servlet need to be cleaned up. This includes thin beans allocated by the servlet for the session. The close method (implemented by QueryClient) should be called to release datasource related resources.
To run the BIStateServlet example within JDeveloper, simply right-click on BIStateServlet.java under state_handling.jpr, and choose Run BIStateServlet.java. When the application appears in a browser, enter the username and password of the user that owns the BI Beans Catalog (e.g. BIBCAT). To demonstrate the state handling, drill down on one dimension of the crosstab and use the browser's back button to go back to the initial state. Then, drill down on another dimension. You will notice that the application is able to identify the state of the application immediately before the second drill so that it just drills down the second dimension. Without state handling, the application would have drilled down on both the first and second dimensions.
![]() |
|
---|---|
Copyright © 2002, 2003 Oracle. All Rights Reserved. |
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. |