A Menu is typically a jsp page that shows all published reports and charts. Depending on the options available, a Menu may allow the user to choose the format in which the report and/or chart are to be presented. The Menus discussed here are analogous to those described in the Menu chapter.
EDAB provides an easy-to-use application programming interface (API) that allows users to create and customize Menus to show in their servlet/jsp applications. This API is written in 100% Pure Java and can be run on any platform with no or few minimal changes. Any and every part of the Menu is customizable using the API.
The main package for EDAB Menu API is the quadbase.reportorganizer.MenuAPI
. Five main classes are associated with this package: MenuNode, MenuTableRow, QbMenu, ScheduleJob
and Util
. The remainder of this chapter will give you an overview of these various classes and their usage. Please note that the complete documentation is located at help/EDABapidocs/index.html.
The jar files for using EDAB Menu API are located in the EDAB/lib
directory. These jar files should already be present in your application's CLASSPATH
when you set up EDAB.
Currently, you can only use EDAB Menu API in a servlet/jsp environment. The servlets/jsps must also run in the same servlet context as EDAB server.
This section discusses the usage of EDAB Menu API with code examples and contains descriptions of the main API classes.
The sections below describe various steps involved in creating and customizing an EDAB Menu:
The first step is to connect to EDAB server. After successfully connected to the server, a QbMenu
object can be allocated. QbMenu
is the main class containing contents for a Menu page.
The EDAB server is simply an object that resides in the ServletContext
of the web application. Since you will want to put most Java code in your Java bean, you will need to pass the HttpServletRequest
and ServletContext
objects from jsp to bean. The following jsp and bean code illustrates this:
Example jsp (Menu_login.jsp
):
<!-- import the bean class --> <%@page language="java" import="help.examples.Menu.exampleMenuLogin"%> <!-- include/instantiate the bean --> <jsp:useBean id="exampleMenuLogin" scope="session" class="help.examples.Menu.exampleMenuLogin" /> <!-- pass the HttpServletRequest and ServletContext objects to the bean --> <% exampleMenuLogin.processRequest(request, application); %>
where the jsp passes the request (HttpServletRequest
) and application (ServletContext
) to the Java bean MenuLogin's processRequest
method. Next, you will need to implement code in the bean that allocates the QbMenu
object from the ServletContext
:
Example bean (MenuLogin.java
):
public void processRequest(HttpServletRequest request, ServletContext context) throws IOException { QbMenu qbMenu = new QbMenu(context.getAttribute(QbMenu.QBMENUDATA)); }
where context.getAttribute(QbMenu.QBMENUDATA)
is set when EDAB server started.
The second step uses the QbMenu
object to authenticate the user. This is easy since all security and permission checks are performed by EDAB server. If login is successful, you can store the QbMenu
object for the session so that for the duration of the session, the user will not have to login again. The following code illustrates this:
boolean loginSuccess = qbMenu.login(userName, password); if (loginSuccess) { //store the QbMenu object in session session.setAttribute("QBMENUOBJ", qbMenu); }
where “QBMENUOBJ
” is the name that you can use later for retrieving the stored QbMenu
. This means that after storing the QbMenu
in the session, you can retrieve it in other jsp pages by doing session.getAttribute("QBMENUOBJ")
. The QbMenu.login
method returns true if and only if the user name and password match. If login failed, the user can be prompted again. Please note that login MUST succeed for the QbMenu
object to return a valid Menu.
After authenticating the user, you can get a list of authorized Menu nodes, which contain reports or charts from the QbMenu
. A node is either a project or a folder in EDAB Organizer.
MenuNode[] MenuNode = qbMenu.getMenuNodeList(null);
Passing in null to the getMenuNodeList
method results in getting all the available Menu nodes. If you pass in a string, the method will return only those nodes items that contain the string.
Please note that the path for the Menu node will be a complete one i.e., Project1/Folder1/SubFolder2
.
Once you have retrieved the Menu nodes, the next step is to get the node details, namely, the files contained in the node. Conceptually, each item in the node is a row and is represented by the MenuTableRow
object. The following code iterates through each file in all nodes:
for (int i = 0; i < MenuNode.length; i++) { for (int j = 0; j < MenuNode[i].getRowItemCount(); j++) { MenuTableRow MenuTableRow = MenuNode[i].getMenuTableRowAt(j); } }
You can obtain all the information of the file (such as file name, description, whether it is a chart or report, etc.) using the MenuTableRow class
.
The following methods are used to obtain the file details:
String getDescription() Returns the description for the row item String getName() Returns the name for the row item String getPath() Returns the path for the row item String getSecurityLevel() Returns the security level for the row item String getURL() Returns the URL for the row item boolean isChart() Returns whether the row item is a chart boolean isReport() Returns whether the row item is a report boolean isDashboard() Returns whether the row item is a dashboard
Using the above methods, you can get the various file details.
Depending on your needs and architecture, you can setup the Menu to show reports and charts in various static formats (such as DHTML, PDF, JPEG, GIF, PNG, etc.) or in an interactive applet. You can code your own servlet using the API's provided in the EDAB Reporting API Overview and EDAB Charting API Overview chapters to get the templates and export them to the format desired.
EDAB also comes with a ready-made servlet that can take different parameters to produce the report and/or chart in the format desired without you having to write any additional servlet code. This servlet is the LookupServlet
servlet and is generally in the EDAB/servlet
context (For example, http://192.168.0.1:8080/EDAB/servlet/LookupServlet
). For more details on this servlet and the various parameters it requires, please refer to the Designer guide.
Javadoc for the entire API is provided along with EDAB. It is located here (server functions).
EDAB already provides a Menu for any user-created reports and/or charts. This Menu can be reached by logging into the Organizer and choosing View Published Dashboards. In addition to this, EDAB also provides an easy-to-use, yet powerful library to create your own Menu in your own styles to display any reports and/or charts.
The jsp code discussed in this chapter is also available in the EDAB/help/examples/Menu
directory (this directory contains both the jsp pages and the css styles). The EDAB/WEB-INF/classes/help/examples/Menu
directory contains the source and class files for the beans. This example demonstrates the steps given above.
Please note that the Menu API requires JDK 1.8 or higher. The EDAB Menu API and jsp pages have been tested with Mozilla (1.3 and above), Firefox (0.91 and above) and Microsoft Internet Explorer (5.x and above) on Windows NT/2000, Solaris, Linux, AIX, and HP platforms.