Setting Thin-Bean State

As you respond to requests in a servlet that includes the BI Beans thin beans, you set the stored state of each thin bean before you handle any thin-bean events in the request. To set the state of a thin bean, you call its setState method. You get the state string to set from the URL or from a UIX State object.

Getting state from the URL and setting it on thin beans

When your application receives requests, you need to retrieve any thin-bean state information that is stored in the URL and set the state on the thin beans. The QueryParameterProvider makes it easier to retrieve state information from the incoming URL. The following code shows how to get thin-bean state from the URL and set it on a thin Explorer Detail. This code assumes that the Explorer Detail is defined as myExplorer. This code also assumes that the ThinBeanName is the HTTP query parameter for the state of a thin bean.


// construct a QueryParameterProvider QueryParameterProvider provider = new ServletQueryParameterProvider(request, response); // set the state on the crosstab myCrosstab.setState(provider.getQueryParameter(myExplorerDetail.getThinBeanName()); // now handle any events from the URL // code not shown in this example

Getting state from a State object and setting it on thin beans

When you store state information in a State object, you need a StateManager from which retrieve the State object. If you store the State objects in the session, then you can use a QueueStateManager to retrieve the State objects. The StateManager interface and the QueueStateManager class are defined in the oracle.cabo.servlet.state package.

If you store State objects in the BI Beans Catalog, then you need a BIStateManager, and you should use checkpointing.

Getting the QueueStateManager

The QueueStateManager manages 20 State objects by default. This allows users to return to 20 different pages in a single session. You can increase this number if you like. For each request, you get the State from the QueueStateManager and set it on the appropriate objects.

The following code shows how to retrieve the QueueStateManager from the HTTP session or how to create the QueueStateManager and store it in the session. This code increases the size of the queue to manage 25 State objects.


// get the StateManager from the HTTP session // httpSession is the HttpSession from the request or a new one StateManager stateManager= (StateManager)httpSession.getAttribute("state_manager"); if (stateManager == null){ stateManager = new QueueStateManager(25); httpSession.setAttribute("state_manager", stateManager); }

Getting state information and setting it on thin beans

When your application receives requests, the URL has the ID of the State object that contains state information. You get this ID from the URL and pass it to the StateManager to get the State object that contains the state strings.

The following code shows one way to get the state from the StateManager and set it on the thin beans in your application. This example assumes that you have a thin crosstab that is defined as myCrosstab and a Query that is defined as myQuery. The example also assumes that you use the ThinBeanName as the key for the state of a thin bean, in the State object.


// get the state ID from the URL // assumes that "stID" is the query parameter for the state ID // first, get a QueryParameterProvider QueryParameterProvider provider = new ServletQueryParameterProvider (request, response); // get the state ID from the QueryParameterProvider String id = provider.getQueryParameter("stID"); // get the state // a MutableState is a State, and you do not need the Mutable part State state = stateManager.getState(id); // assumes that you use the ThinBeanName as the key in the State // get the crosstab state and set it on the crosstab String name = myCrosstab.getThinBeanName(); myCrosstab.setState(state.getValue(name)); // get the query state and set it name = myQuery.getThinBeanName(); myQuery.setState(state.getValue(name));

If you use the ServletRequestHandler, then you can set the state of all of the registered thin beans, using code such as the following example. You get the State from the QueueStateManager as in the previous example. Also, as in the previous example, this example assumes that you use the ThinBeanName as the key to the state information.


// get a QueryParameterProvider QueryParameterProvider provider = new ServletQueryParameterProvider (request, response); // get the state id String id = provider.getQueryParameter("stID"); // get the state State state = stateManager.getState(id); // get the ServletRequestHandler from the session ServletRequestHandler requestHandler = httpSession.getAttribute("request_handler"); // set the state requestHandler.setState(state); // now handle any events requestHandler.handleEvent(provider);

Managing State in an HTML-Client Application
Getting Thin-Bean State
BI Beans Request-Handling Sequence
Checkpointing Thin-Bean State
Rendering Thin Beans