The menu page and URL publishing options provide a convenient deployment vehicle for reports and charts. Using these interfaces, users can easily deploy charts and reports to the Web without any coding. However, by themselves these interfaces do not provide any significant run-time customization capability. Report and chart templates are run in a pretty much “as is” format.
For users who would like to provide some additional logic or run-time customization to reports and charts, EDAB provides the Menu Page Listener interface which is part of the EDAB extension package. Using this method, users can implement listeners that will intercept the report or chart prior to export and use the APIs to modify it.
The EDAB Listener Manager
is a user-implemented class that is used to manage several listeners that monitor events on the server, including the Menu Page Listener
. In order to implement the Menu Page Listener
, users must implement the Listener Manager
. Below is a sample Listener Manager
class:
package extensionClasses; import quadbase.reportorganizer.ext.*; public class MyEdabListenerManager extends DefaultListenerManager { public MyEdabListenerManager() {} // not used. Always returns null public EdabSchedulerListener getSchedulerListener() { return null(); } public MenuPageListener getMenuPageListener() { return new MyMenuPageListener(); } }
Users can impelement the EDABListenerManager
interface or extend DefaultListenerManager
. The above code implements the Menu Page Listener
(note that the Scheduler Listener
always returns null).
You can specify the Listener Manager
class as a server option for EDAB. You can set this in one of two places. The first option is the Admin Console. You can specify the class in the Server Options tab. You can also specify the class by modifying the QB.properties
under <EDABInstallDir>/WEB-INF/classes
. For more information about server configuration options, see Section 1.4.1.3 - Server Options.
The following code shows a sample implementation of the Menu Page Listener
:
package extensionClasses; import java.lang.*; import java.awt.*; import quadbase.reportorganizer.ext.*; import quadbase.reportdesigner.ReportAPI.*; import quadbase.reportdesigner.ReportElements.*; import quadbase.reportdesigner.util.*; import quadbase.ChartAPI.*; import quadbase.reportdesigner.report.Formula; public class MyMenuPageListener implements MenuPageListener { // Note that ... is not valid and is just an example String databaseURL = "..."; String databaseDriver = "..."; String databaseUID = "..."; String databasePwd = "..."; public QbReport modifyBeforeRun(QbReport report, String username) { System.out.println("Calling Menu Page Listener..."); try { // Change the datasource of the report report.getInputData().setAllDatabaseInfo(databaseURL, databaseDriver, databaseUID, databasePwd); } catch (Exception ex) { ex.printStackTrace(); } return report; } public QbChart modifyBeforeRun(QbChart chart, String username) { System.out.println("Calling Menu Page Listener"); try { // Change the datasource of the chart quadbase.ChartAPI.DBInfo newChartDataSource = new quadbase.ChartAPI.DBInfo(databaseURL, databaseDriver, databaseUID, databasePwd, chart.gethInputData().getDatabaseInfo().getQuery()); chart.gethInputData().setDatabaseInfo(newChartDataSource); } catch (Exception ex) { ex.printStackTrace(); } return chart; } }
This example implements two “modifyBeforeRun” methods, one for charts and one for reports. With this code deployed, every time a report or chart is run, the datasource is changed to the one specified in the code. Note that for best results, the report and/or chart should be using a database datasource originally and the new datasource must return a result set for the original queries.
This example shows the most common scenario where the Listeners are used. Note that any report/chart API code can be used in these interfaces to modify the reports and charts prior to export. You can refer to the java documentation to learn more about the API available.