The BIToolbarServlet demonstrates how the toolbar interacts with a view in a servlet application. The class inherits user login functionality from BIServlet. The sample displays a view and a toolbar. The toolbar displays the following tools, which can be used to manipulate the view.
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.
Presentation presentation = new Presentation(ViewTypeTool.CROSSTAB);
presentation.setThinBeanName(PRESENTATION_NAME);
ThinDataviewCommon crosstab = presentation.getView();
crosstab.setPagingControlVisible(true);
crosstab.setDataSource(dataSource);
handler.registerThinBean(presentation);
After we have a view, the toolbar is initialized and hooked up with the view. The following code initializes the toolbar.
ViewToolbar viewToolbar = new ViewToolbar();
viewToolbar.setThinBeanName (TOOLBAR_NAME);
viewToolbar.setView(crosstab);
viewToolbar.addViewToolListener (new ViewToolAdapter(biHttpSession));
handler.registerThinBean(viewToolbar);
The application adds a ViewToolListener
with the ViewToolbar
thin bean. The thin bean fires an event when an event occurs on the client.
The application can change the displayed view type when the event occurs.
The application delegates to the ServletRequestHandler
for handling
thin-bean events.
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 ( );
FormBean
UIX component.
FormBean rootNode = new FormBean (
FORM_NAME );
ViewToolbar viewToolbar = ( ViewToolbar ) handler.getThinBean (
TOOLBAR_NAME );
if ( viewToolbar != null ) {
ViewToolbarBean viewToolbarBean = new ViewToolbarBean (
viewToolbar );
rootNode.addIndexedChild ( viewToolbarBean );
}
FormBean
UIX component are rendered
as follows:
ServletRenderingContext renderingContext =
new ServletRenderingContext( this, request, response, out );
rootNode.render ( renderingContext );
If the url contains a thin-bean event, then the event and the target bean of the event are displayed on the page.
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. |