Report Viewing Interactivity - Custom Buttons

This chapter presents a example that shows how to add report viewing interactivity with a custom refresh button. Since there is already a refresh button on the viewer, this does not necessarily have to be done with the custom button mechanism, but it does represent a simple example of using the feature.

To create a button, we first create a class to define the custom button. The class implements the ViewerAction interface. A graphic icon needs to be created to represent the button on the viewer. After the icon is created, it should be placed on the classpath so it can be accessed as a resource.

 public String getIconResource() {
 return "/images/dbRefresh.gif"; 
 } 

This means the GIF file should be placed in a directory called 'images' on the classpath or in a JAR file.

monitoring dashboard  
demo
View a 2-minute demo of InetSoft's easy, agile, and robust BI software.

Next, we define the label for the button.

 public String getLabel() {
 return "Refresh DB"; 
 } 

Finally, the class needs to define the actionPerformed() method, which accepts four parameters: a replet ID, the replet repository instance, the replet object where the action is invoked and the repletRequest object. It is free to perform any actions in the method and can return a RepletCommand to direct the viewer to execute one or more viewer actions.

public RepletCommand actionPerformed(Object rid, 
RepletRepository repo, Replet replet, RepletRequest req) { 
// actions, such as refreshing the database data
   return RepletCommand.refresh(); // refresh report 
}

Configuring a Custom Button

Once the custom button class is created, it needs to be registered with the viewer so it will be added to the toolbar. To register the button in the viewer, add a replet.viewer.actions property to the sree.properties file. The value for the property is the fully qualified class name of the custom button class. If more than one button needs to be added, they can be included in the property using a comma-separated list.

replet.viewer.actions=com.mycompany.buttons.DBRefresh
Previous: Browse Reports From a Web Browser