rBlox.setInteractive(true);
BloxContext context = BloxContextFactory.getBloxContext(request, response); rBlox.setUrlPrefix(context.getContextPath() + "/" + URLFactory.ALPHABLOX_SERVER_PREFIX);
String scriptId = rBlox.getBloxName();
if(scriptId == null)
{
scriptId = rBlox.getId();
}
rBlox.init(context,scriptId);
This piece of code registers the ReportBlox
with the BloxContext using the optional bloxName if it is specified.
If not, it uses the Blox id. The complete example is now as follows:
<%@ page import="com.alphablox.blox.*,
com.alphablox.net.URLFactory"
<html>
<head>
<link rel="stylesheet" href="/AlphabloxServer/theme/report.css" />
</head>
<body>
<%
String query="SELECT Week_Ending, location, product_name, sales, units, cost
FROM qcc WHERE Week_Ending_Text = '04-08-2000'";
try {
ReportBlox rBlox = new ReportBlox();
rBlox.setErrors(true);
rBlox.setId("myRBlox");
// 1. Set the ReportBlox to interactive
rBlox.setInteractive(true);
DataSourceConnectionBlox dConn = new DataSourceConnectionBlox();
dConn.setDataSourceName("qcc2003-rdb");
dConn.connect();
SQLDataBlox dBlox = new SQLDataBlox();
dBlox.setInput(dConn);
dBlox.setQuery(query);
dBlox.execute();
// Create the grouping
GroupBlox myGroup = new GroupBlox();
myGroup.setMembers( new String [] {"location"});
myGroup.setAggregationType("units", "none");
// Set up the input for the group
myGroup.setInput(dBlox);
rBlox.setInput(myGroup);
// 2. Set the URL prefix
BloxContext context = BloxContextFactory.getBloxContext(request, response);
rBlox.setUrlPrefix(context.getContextPath() + "/" +
URLFactory.ALPHABLOX_SERVER_PREFIX);
// 3. Add the ReportBlox to the Context
String scriptId = rBlox.getBloxName();
if(scriptId == null)
{
scriptId = rBlox.getId();
}
rBlox.init(context,scriptId);
// Finally call ReportBlox’s write() method to write it out
rBlox.write(out);
}
catch ( Exception e ) {
ErrorBlox eBlox = new ErrorBlox();
Throwable msg = eBlox.getRootCause(e);
out.println("<br><b> This Exception was captured</b><br> "+
msg.getMessage());
}
</body>
</html>
You probably have found that it is a lot more convenient to use tags to create your relational report. You can always script to the objects using their id when you need to.