Tutorial 10: Changing parameter values and definitions
This tutorial provides step-by-step instructions for authoring a web page that implements the parameterValue and parameterDefinition classes to set parameter values and control the visibility of parameters in a BIRT report displayed in BIRT Viewer. You perform the following tasks:
*Create a web page that processes parameters.
*Display a hidden parameter using ParameterDefinition.
The file in this tutorial with a hidden parameter is Sales by Territory.rptdesign.
Task 1: Create a web page that processes parameters
In this task, you open or create a copy of JSAPITemplate.html and edit its contents to display a parameter and pass the value selected by the user to a BIRT report displayed in BIRT Viewer.
1 Using a code editor, open or create a JSAPITemplate.html file that contains the essential components for any web page that implements the JSAPI.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type"
content="text/html;charset=utf-8" />
<title>JSAPI Template</title>
</head>
<body onload="init( )">
<div id="sample">
<script type="text/javascript" language="JavaScript" src="http://127.0.0.1:8700/iportal/jsapi"></script>
<script type="text/javascript" language="JavaScript">
<!-- Insert code here -->
</script>
</div>
</body>
</html>
2 Navigate to the following line:
<title>JSAPI Template</title>
In title, change:
JSAPI Template
to:
Viewer with Parameters Page
3 Navigate to the following line:
<div id="sample">
In id, change:
sample
to:
parampane
4 Navigate to the empty line after the following line:
<script type="text/javascript" language="JavaScript">
5 Add the following code:
function init( ){
actuate.load("viewer");
actuate.load("parameter");
actuate.initialize( "http://127.0.0.1:8700/iportal", null, "administrator", "", displayParams);
}
function displayParams( ) {
param = new actuate.Parameter("parampane");
param.setReportName("/Applications/BIRT Sample App
/Sales by Territory.rptdesign");
param.submit(function ( ) {document.getElementById("run").style.visibility = 'visible';} );
}
function processParameters( ) {
param.downloadParameterValues(runReport);
}
</script>
</div>
 
<hr><br />
<input type="button" class="btn" id="run" name="run"
value="Run Report" onclick="processParameters( )">
 
<div id="viewerpane">
<script type="text/javascript" language="JavaScript"
src="http://127.0.0.1:8700/iportal/jsapi"></script>
<script type="text/javascript" language="JavaScript">
function runReport(paramvalues) {
var viewer = new actuate.Viewer("viewerpane");
viewer.setReportName("/Applications/BIRT Sample App
/Sales by Territory.rptdesign");
viewer.setParameterValues(paramvalues);
viewer.submit( );
}
6 Save the file as processparameters.htm.
7 In Internet Explorer, open processparameters.htm.
If you receive a security warning that Internet Explorer has restricted this page from running scripts or ActiveX controls that could access your computer, right-click on the message and select Allow Blocked Content.
8 On Please specify a territory, choose Japan, then choose Run Report. The Sales by Territory report for Japan appears, as shown in Figure 16‑7.
Figure 16‑7 Sales by Territory for Japan
Task 2: Display a hidden parameter using ParameterDefinition
In this task, you display a hidden parameter. Sales by Territory.rptdesign has two parameters, currentYear and Territory, but currentYear is a hidden parameter. To display currentYear, you use parameterDefinition to show the parameter normally.
1 Using a code editor, open processparameters.htm.
2 Navigate to the following line:
param.submit(function ( ) {document.getElementById("run").style.visibility = 'visible';} );
Replace the line with the following two lines:
param.submit( );
param.downloadParameters(changeText);
3 Add the changeText function to the parampane div element, as shown in the following code:
<div id="parampane">
<script type="text/javascript" language="JavaScript"
src="http://127.0.0.1:8700/iportal/jsapi"></script>
<script type="text/javascript" language="JavaScript">
function init( ) {
actuate.load("viewer");
actuate.load("parameter");
actuate.initialize( "http://127.0.0.1:8700/iportal", null, "administrator", null, displayParams);
}
function displayParams( ) {
param = new actuate.Parameter("parampane");
param.setReportName("/Applications/BIRT Sample App
/Sales by Territory.rptdesign");
param.submit( );
param.downloadParameters(changeText);
}
function processParameters( ) {
param.downloadParameterValues(runReport);
}
function changeText( paramdef ) {
paramdef[0].setIsHidden(false);
param.renderContent( paramdef );
}
</script>
</div>
4 Save the file as displayparameters.htm.
5 In Internet Explorer, open displayparameters.htm.
If you receive a security warning that Internet Explorer has restricted this page from running scripts or ActiveX controls that could access your computer, right‑click on the message and select Allow Blocked Content.
6 The currentYear parameter for Sales by Terrritory.rptdesign appears, as shown in Figure 16‑8.
Figure 16‑8 currentYear parameter displayed on a web page