Class AggregatedEventHandler

  • All Implemented Interfaces:
    WebEventHandler, WebEventTags, java.lang.Cloneable
    Direct Known Subclasses:
    AggregatedAppEventHandler, AggregatedFolderEventHandler, AggregatedReportSavePropertiesEventHandler, ReportPageEventHandler, RWBeanHTML5VIEventHandler

    public abstract class AggregatedEventHandler
    extends GenericEventHandler
    The AggregatedEventHandler class is intended for customization of existing event handlers. By extending this abstract class, a customized event handler can change the way events are processed, extend the definition of existing events, and create new events.

    An instance of this class aggregates a "default" event handler. A custom event handler subclass can either handle a given event itself or delegate it to the aggregated default handler.

    Custom event handler subclasses must implement the abstract method processRequest, which serves as the entrypoint for event processing. From there, the custom handler can choose to handle a given event itself, or delegate it by calling handleDefaultRequest.

    The default event handler is set via the setDefaultHandler method. Typically, it is not necessary for custom event handler implementations to explicitly call this method. By default, when the system creates an AggregatedEventHandler to be associated with a given bean, it will use the bean's event handler as the default handler (see the example below).

    The following code shows a custom event handler that can be associated with a FolderBean:

     public class CustomFolderHandler extends AggregatedEventHandler {
         public boolean processRequest(RequestKeys keys) throws WebException {
             int eventID = getEventID(keys);
             switch (eventID) {
                 // handle desired events here
             }
    
             // or delegate to the default handler
             return handleDefaultRequest(keys);
         }
     }
     
    To associate this event handler with a bean, update the bean's <web-bean> node in pageConfig.xml.
    Typically, the line in pageConfig.xml that specifies a given bean looks like:
       <web-bean name="fb" persist-mode="2" sys-bean="FolderBean"/>
     
    We use the event-handler attribute to associate a custom event handler with that bean:
       <web-bean name="fb" persist-mode="2" sys-bean="FolderBean" event-handler="com.xyz.CustomFolderHandler"/>
     

    where com.xyz.CustomFolderHandler is the fully qualified class name of the custom event handler class.

    At runtime, when the bean shown above needs to be created, the system will first instantiate a new FolderBean instance. It will then create a new CustomFolderHandler instance that aggregates the FolderBean instance's event handler. Finally, it will call WebComponent.setWebEventHandler to associate the CustomFolderHandler instance with the FolderBean instance.

    Since:
    MicroStrategy Web 7.3.1 or earlier
    • Field Detail

      • defaultHandler

        protected WebEventHandler defaultHandler
        The default event handler.
    • Constructor Detail

      • AggregatedEventHandler

        @Deprecated
        protected AggregatedEventHandler​(int type)
        Deprecated.
        Use the no-arg constructor, along with setDefaultHandler if necessary. For flexibilty reasons, this class should no longer be responsible for creating the default handler based on its type.
        Constructs an AggregatedEventHandler with the specified event handler type. Internally calls setHandlerType, which creates an instance of the event handler with the specified type and sets it to be the default handler.
        Parameters:
        type - the event handler type.
      • AggregatedEventHandler

        protected AggregatedEventHandler()
        Constructs an AggregatedEventHandler without a default handler. Code that creates an AggregatedEventHandler instance programmatically can call setDefaultHandler to set the default handler.
        Since:
        MicroStrategy Web 9.0.0
    • Method Detail

      • getWebEvent

        public WebEvent getWebEvent​(int id)
        Returns the specified WebEvent instance which this event handler supports.
        Specified by:
        getWebEvent in interface WebEventHandler
        Overrides:
        getWebEvent in class GenericEventHandler
        Parameters:
        id - the event id of the WebEvent.
        Returns:
        the specified WebEvent; null if the event is not supported by this event handler.
      • delegateRequest

        public boolean delegateRequest​(RequestKeys keys)
                                throws WebException
        Description copied from class: GenericEventHandler
        The default implementation of this method simply delegates the event to the next source component specified in the static field GenericWebEvent.URL_SOURCE_NAME.
        Specified by:
        delegateRequest in interface WebEventHandler
        Overrides:
        delegateRequest in class GenericEventHandler
        Parameters:
        keys - the RequestKeys object containing event ID, sources, and any other information.
        Returns:
        true if handling succeeds in processRequest or one of its children.
        Throws:
        WebException - thrown if handling of the request fails.
        Since:
        MicroStrategy Web 7.5.4
      • setHandlerType

        protected void setHandlerType​(int type)
        Sets the event handler type. This implementation creates a new instance of the event handler with the specified type and sets it to be the default handler. Can be overridden in subclasses to change the way default handlers are created.

        NOTE: This implementation is provided for backward compatibility only. New code should set the default handler using setDefaultHandler.

        Overrides:
        setHandlerType in class GenericEventHandler
        Parameters:
        type - the event handler type.
      • setDefaultHandler

        public void setDefaultHandler​(WebEventHandler handler)
        Sets the default event handler.
        Parameters:
        handler - A WebEventHandler instance to use as the default event handler.
        Since:
        MicroStrategy Web 9.0.0
      • getDefaultHandler

        public WebEventHandler getDefaultHandler()
        Returns the default event handler.
        Returns:
        WebEventHandler The default event handler, or null if no default event handler has been set.
        Since:
        MicroStrategy Web 9.0.0
      • handleDefaultRequest

        protected boolean handleDefaultRequest​(RequestKeys keys)
                                        throws WebException
        Asks the default event handler to handle the request.
        Parameters:
        keys - the RequestKeys object containing event ID, sources, and any other information.
        Returns:
        true if handling succeeds; false if the event is ignored and not handled.
        Throws:
        WebException