Using RDBResultSetDataBlox to access RDBResultSet from DataBlox

Another way data can be fed to a ReportBlox is via a RDBResultSetDataBlox. RDBResultSetDataBlox allows you to create a relational report using the RDBResultSet returned from an existing DataBlox. DataBlox provides data to user interface Blox such as PresentBlox, GridBlox, and ChartBlox (tags for these Blox are in the Blox Tag Library, available with the <%@ taglib uri="bloxtld" prefix="blox" taglib directive). DataBlox cannot provide data directly to ReportBlox. However, RDBResultSet returned from a DataBlox can be used as the source of data for Relational Reporting via RDBResultSetDataBlox. This is useful for applications where relational details for data in a GridBlox cell from a multidimensional data source can be presented in an attractive, easy-to-read layout.

Alphablox’s drill-through support for Microsoft® Analysis Services data sources in GridBlox and DataBlox, for example, uses a RDBResultSetDataBlox that takes the DataBlox’s RDBResultSet to generate a relational report with ReportBlox. You simply set the GridBlox drillThroughEnable property to true and no custom code is needed. When users choose to drill through from a data cell, relational detail for the cell is displayed in a pre-formatted report using ReportBlox.

For custom report, you can supply your own JSP containing a ReportBlox formatted to you liking. A live example is available in the MSAS version of Blox Sampler, under the Retrieving Data section.

To feed the RDBResultSet of a DataBlox to a ReportBlox, in the calling JSP containing the GridBlox (or PresentBlox), you should call the JSP containing the ReportBlox by passing along three pieces of information:
  • The id of the DataBlox whose RDBResultSet the ReportBlox will use as the data producer.
  • The coordinates (colIndex and rowIndex) of the cell whose relational details is requested.

The JSP containing the ReportBlox may looks as follows:

<%@ taglib uri="bloxreporttld" prefix="bloxreport" 
<html>
<head>
   <link rel="stylesheet" href="/AlphabloxServer/theme/report.css" />
</head>
<body>

<bloxreport:report id="drillThroughFromDataBlox" ...>
   <bloxreport:rdbResultSetData
      bloxRef="myDataBlox"
      columnCoordinate="<%= request.getParameter(\"colIndex\") "
      rowCoordinate="<%= request.getParameter(\"rowIndex\") "
   />

   <%--further data manipulation and report formatting--
   ... 

</bloxreport:report>
</body>
</html>

The value for the bloxRef attribute should be the id of the DataBlox defined in the calling JSP. The colIndex and rowIndex parameters are passed in from a scriptlet or Java™ class from the DHTML client in the calling JSP.

For example, assume the calling JSP has a DataBlox as follows:
<blox:data id="myDataBlox"
   dataSourceName="QCC-MSAS"
   selectableSlicerDimensions="Measures"
   query="yourQueryString"/>
For the DHTML client, you may have a PresentBlox that uses myDataBlox:
<%@ taglib uri="bloxtld" prefix="blox"
<%@ taglib uri='bloxuitld' prefix='bloxui'
...
<body>
<blox:present id="myPresentBlox" 
   width="700" 
   height="580">
   <blox:data bloxRef="myDataBlox"/>
   <blox:grid drillThroughEnabled="true" />
   <bloxui:actionFilter 
      className="<%= myCustomDrillThrough.class.getName() "
          componentName="dataAdvancedDrillThrough" />
</blox:present>
...
When the user chooses the Advanced... > Drill through option from the right-click menu (componentName = "dataAdvancedDrillThrough"), the myCustomDrillThrough class is called. The class may look as follows:
import com.alphablox.blox.uimodel.core.grid.GridCell;
import com.alphablox.blox.uimodel.tags.IActionFilter;
...
public class myCustomDrillThrough implements IActionFilter
{
   public void actionFilter( DataViewBlox blox, Component component )
throws Exception {
      GridBrixModel grid = 
((PresentBloxModel)blox.getBloxModel()).getGrid();
      GridCell[] cells = grid.getSelectedCells();
      // Make sure that a single data cell is selected
      if ( cells.length != 1 || cells[0].isRowHeader() ||
cells[0].isColumnHeader() || !(cells[0] instanceof GridBrixCellModel )) 
      {
         MessageBox.message( component, "Error", "You must select a 
single data cell to drill through" );
        return;
      }

      GridBrixCellModel cell = (GridBrixCellModel)cells[0];
      int rowIndex = cell.getNativeRow();
      int colIndex = cell.getNativeColumn();
      String bloxName = blox.getBloxName();

      String urlStr = "myDrillThrough.jsp?bloxRef="+bloxName;
      urlStr += "&colIndex=";
      urlStr += colIndex;
      urlStr += "&rowIndex=";
      urlStr += rowIndex;
      String timestamp = String.valueOf(System.currentTimeMillis());
      urlStr += "&reportName=";
      urlStr =  urlStr + "reportBlox"+timestamp;

      ClientLink link =  new ClientLink( urlStr, 
"reportBlox"+timestamp);
      component.getDispatcher().showBrowserWindow( link );
   }
}

For a complete example, see the Retrieving Data section under Blox Sampler.

If you are using the Java client, you can use the eventTriggerDrillThrough JavaScript™ callback property:
<blox:data
<blox:present id="myPresentBlox" 
   mayscriptEnabled="true"
   width="700" 
   height="580">
   <blox:data 
      bloxRef="myDataBlox"/>
   <blox:grid 
      drillThroughEnabled="true" 
      eventTriggerDrillThrough="multipleDTWindows"/>
</blox:present>
When the user chooses to drill through, a JavaScript function called multipleDTWindow in the same calling JSP gets triggered :
...
<head>
<blox:header/>

<script language="JavaScript">
function multipleDTWindows(var1,var2,var3) {
   var bloxName;
   var colIndex;
   var rowIndex;
   var eventObj = var1;

   bloxName = "myDataBlox";
   colIndex = eventObj.getEventProperty(eventObj, "column");
   rowIndex = eventObj.getEventProperty(eventObj, "row");

   var urlStr = "someReportBlox.jsp?bloxRef="+bloxName;
   urlStr += "&colIndex=";
   urlStr += colIndex;
   urlStr += "&rowIndex=";
   urlStr += rowIndex;
   var currentDate = new Date();
   var timestamp = currentDate.getTime();
   urlStr += "&reportName=";
   urlStr =  urlStr + "reportBlox"+timestamp;
   window.open(urlStr,"reportBlox"+timestamp);
   return false;
}
</script>
</head>

For a complete example, see the Retrieving Data section in Blox Sampler.