InetSoft Documentation: Report Programming - Customization Parameters

The previous two types of parameters are both for creating a report. After a report object is created, there are many ways that it can be modified by the users. One of these is the predefined 'Customize' parameter. We will discuss more interactions in the Event Handling chapter. The 'Customize' parameter is a special parameter that is recognized and processed by the replet environment.

If a replet declares a 'Customize' parameter, a 'Customize' button is placed on the viewer window. When the button is clicked, the viewer pops up a request dialog with the specified customization parameters. After the user clicks 'OK' on the dialog, a RequestEvent is sent to the replet. By default, when a RequestEvent is received at a replet, the createReport() is called with the request object and the report is refreshed with the new report object returned from the method. A program can also override the default handling and process the RequestEvent directly. We will cover the event handling process in more detail in the 'Event Handling' section.

A replet can have code in the createReport() method to modify the existing report using the parameters in the customization request. It can even create a completely new report object if it chooses to. This customization method is very simple from both the programmers and end users' point of view and is the preferred method for report customization.

Example: Customization Parameter

We change the previous example by adding a 'Customize' parameter to the replet. The parameter controls the visibility of the report title.

Customizable Report

package inetsoft.demo.replets;
 
import inetsoft.sree.*;
import inetsoft.report.*;
import inetsoft.report.chart10.*;
import inetsoft.report.io.*;
import inetsoft.report.lens.*;
import java.util.*;
import java.io.*;
 
 
public class Replet4 extends BasicReplet {
public void init(RepletRequest req) throws
RepletException {
try {
// load the report template
InputStream input = getClass().
getResourceAsStream("/" + req.getParameter("templateName") + ".srt");
 
Builder builder = Builder.getBuilder(Builder.TEMPLATE, input);
report = (ReportSheet) builder.read(".");
 
// load data from data file
InputStream input2 =
getClass().getResourceAsStream("/data/education.csv");
 
ttl = new TextTableLens(input2,",");
ttl.setHeaderRowCount(1);
 
RepletParameters def =
new RepletParameters(RepletRequest.CUSTOMIZE);
 
def.addBoolean("Show Title", true);
 
def.addParameter("Title", "", null);
def.setVisible("Title", false);
 
RepletParameters def1 = new
RepletParameters(RepletRequest.CREATE);
def1.addParameter("Title", "", null);
 
def1.addBoolean("Show Title", true);
def1.setVisible("Show Title", false);
 
addRepletParameters(def);
addRepletParameters(def1);
 
} catch(Exception e) {
e.printStackTrace();
throw new RepletException(e.getMessage());
}
}
public ReportSheet createReport(RepletRequest req) {
 
// set the data on the template
report.setElement("Table1", ttl);
 
//set the text value to the title
report.setElement("Text1", req.getString("Title"));
 
report.getElement("Text1").setVisible(req.getBoolean("Show Title"));
 
return report;
}
 
ReportSheet report;
TextTableLens ttl;
}

Notice how we add all parameters (customization and creation) to each RepletParameter object. This is so that none of the creation parameter values get lost when we refresh the report with the customization parameters.We add this replet to the repository, then use the web viewer to view it

Notice that the 'Customize' button is activated on the report toolbar on the requested report. A small 'Customize' button is also placed on the status bar of the viewer window as an extra visual indication. Clicking on either of the buttons brings up the customization dialog. In this example, a 'Show Title' checkbox will appear in the customization dialog.

Unselect the checkbox and submit the customization request (set the title to be invisible). The report is refreshed to show the new presentation option without the report title.

Previous: Report Programming - Initialization Parameters