Strategy ONE
Adding an Event Handler to a New or Custom Bean
If a bean simply reads data from a data source and displays it on a MicroStrategy Web page, there is no need for an event handler. However, if the bean needs to change the data or perform some actions based on user interactions, you must add an event handler to the bean. You can do this easily using the Web Customization Editor. Refer to Adding an Event Handler to a Bean for detailed instructions on how to do this.
During the process of adding an event handler, the Web Customization Editor creates an event handler class with template code. You can either copy the code from an existing event handler class that performs the required actions or you can create a new event handler class by writing you own code in place of the template code. This event handler class must define the events to which the bean reacts and perform the actions required by these events. It must extend either AggregatedEventHandler or GenericEventHandler. Sample code is provided below for creating a custom event handler class.
Creating a custom event handler class
-
Creating an event handler for a new bean based on an existing system bean
If you are creating a custom event handler class for a new bean that is based on an existing system bean, the event handler class must extend com.microstrategy.web.beans.AggregatedEventHandler. This ensures that the event handler can initialize itself with events. Extending this abstract class allows a custom event handler to extend the definition of existing events, create new events, and create a new event handler of an existing type. In addition, the customized event handler is also able to delegate an event to an aggregated default event handler compatible with the customized event handler through the method call handleDefaultRequest(RequestKeys), if the customized event handler decides not to handle the event.
The custom event handler must have the following two methods:
-
A protected constructor that assigns a type to this event handler, as illustrated in the code snippet below.
protected CustomBeanEventHandler(){
super();
}
-
A processRequest() method that overrides the default method in the abstract class.
By default, the processRequest() method is invoked by the handleRequest() method, which accepts the information from the request, identifies the appropriate instance of WebEvent, and then determines the actions based on the event.
public boolean processRequest(RequestKeys keys) throws WebException {
//Get the event requested from the RequestKeys
WebEvent event = getWebEvent(keys);
//process event here
return true;
//or delegate to super class
return super.processRequest(keys);
}
-
-
Creating an event handler for a custom bean
If you are creating a custom event handler class for a custom bean (that is, an entirely new bean that is not based on an existing system bean), you must extend the GenericEventHandler and define the events and their arguments within the event handler class itself.
