org.apache.click
Class ActionEventDispatcher

java.lang.Object
  extended by org.apache.click.ActionEventDispatcher

public class ActionEventDispatcher
extends Object

Provides a control ActionListener and AjaxBehavior dispatcher. The ClickServlet will dispatch registered ActionListeners and AjaxBehaviors after page controls have been processed.

Example Usage

The following example shows how to register an ActionListener with a custom Control:
 public class MyControl extends AbstractControl {
     ...

     public boolean onProcess() {
         bindRequestValue();

         if (isClicked()) {
             // Dispatch an action listener event for invocation after
             // control processing has finished
             dispatchActionEvent();
         }

         return true;
     }
 } 
When the link is clicked it invokes the method AbstractControl.dispatchActionEvent(). This method registers the Control's action listener with the ActionEventDispatcher. The ClickServlet will subsequently invoke the registered ActionListener.onAction(Control) method after all the Page controls onProcess() method have been invoked.


Constructor Summary
ActionEventDispatcher(ConfigService configService)
          Construct the ActionEventDispatcher with the given ConfigService.
 
Method Summary
static void dispatchActionEvent(Control source, ActionListener listener)
          Register the event source and event ActionListener to be fired by the ClickServlet once all the controls have been processed.
static void dispatchAjaxBehaviors(Control source)
          Register the source control which AjaxBehaviors should be fired by the ClickServlet.
protected  void errorOccurred(Throwable throwable)
          Allow the dispatcher to handle the error that occurred.
protected  boolean fireActionEvent(Context context, Control source, ActionListener listener)
          Fire the action for the given listener and event source which return true if the page should continue processing.
 boolean fireActionEvents(Context context)
          Fire all the registered action events after the Page Controls have been processed and return true if the page should continue processing.
protected  boolean fireActionEvents(Context context, List<Control> eventSourceList, List<ActionListener> eventListenerList)
          Fire the actions for the given listener list and event source list which return true if the page should continue processing.
 boolean fireAjaxBehaviors(Context context)
          Fire all the registered AjaxBehaviors and return true if the page should continue processing, false otherwise.
protected  boolean fireAjaxBehaviors(Context context, Control source)
          Fire the AjaxBehaviors for the given control and return true if the page should continue processing, false otherwise.
protected  boolean fireAjaxBehaviors(Context context, Set<Control> ajaxBbehaviorSourceSet)
          Fire the AjaxBehaviors for the given control set and return true if the page should continue processing, false otherwise.
static ActionEventDispatcher getThreadLocalDispatcher()
          Return the thread local ActionEventDispatcher instance.
static boolean hasThreadLocalDispatcher()
          Returns true if an ActionEventDispatcher instance is available on the current thread, false otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActionEventDispatcher

public ActionEventDispatcher(ConfigService configService)
Construct the ActionEventDispatcher with the given ConfigService.

Parameters:
configService - the click application configuration service
Method Detail

dispatchActionEvent

public static void dispatchActionEvent(Control source,
                                       ActionListener listener)
Register the event source and event ActionListener to be fired by the ClickServlet once all the controls have been processed.

Parameters:
source - the action event source
listener - the event action listener

dispatchAjaxBehaviors

public static void dispatchAjaxBehaviors(Control source)
Register the source control which AjaxBehaviors should be fired by the ClickServlet.

Parameters:
source - the source control which behaviors should be fired

getThreadLocalDispatcher

public static ActionEventDispatcher getThreadLocalDispatcher()
Return the thread local ActionEventDispatcher instance.

Returns:
the thread local ActionEventDispatcher instance.
Throws:
RuntimeException - if an ActionEventDispatcher is not available on the thread

hasThreadLocalDispatcher

public static boolean hasThreadLocalDispatcher()
Returns true if an ActionEventDispatcher instance is available on the current thread, false otherwise.

Unlike getThreadLocalDispatcher() this method can safely be used and will not throw an exception if an ActionEventDispatcher is not available on the current thread.

Returns:
true if an ActionEventDispatcher instance is available on the current thread, false otherwise

fireActionEvents

public boolean fireActionEvents(Context context)
Fire all the registered action events after the Page Controls have been processed and return true if the page should continue processing.

Parameters:
context - the request context
Returns:
true if the page should continue processing, false otherwise

fireAjaxBehaviors

public boolean fireAjaxBehaviors(Context context)
Fire all the registered AjaxBehaviors and return true if the page should continue processing, false otherwise.

Parameters:
context - the request context
Returns:
true if the page should continue processing, false otherwise
See Also:
fireAjaxBehaviors(org.apache.click.Context, java.util.Set)

errorOccurred

protected void errorOccurred(Throwable throwable)
Allow the dispatcher to handle the error that occurred.

Parameters:
throwable - the error which occurred during processing

fireActionEvents

protected boolean fireActionEvents(Context context,
                                   List<Control> eventSourceList,
                                   List<ActionListener> eventListenerList)
Fire the actions for the given listener list and event source list which return true if the page should continue processing.

This method can be overridden if you need to customize the way events are fired.

Parameters:
context - the request context
eventSourceList - the list of source controls
eventListenerList - the list of listeners to fire
Returns:
true if the page should continue processing or false otherwise

fireActionEvent

protected boolean fireActionEvent(Context context,
                                  Control source,
                                  ActionListener listener)
Fire the action for the given listener and event source which return true if the page should continue processing.

This method can be overridden if you need to customize the way events are fired.

Parameters:
context - the request context
source - the source control
listener - the listener to fire
Returns:
true if the page should continue processing, false otherwise

fireAjaxBehaviors

protected boolean fireAjaxBehaviors(Context context,
                                    Set<Control> ajaxBbehaviorSourceSet)
Fire the AjaxBehaviors for the given control set and return true if the page should continue processing, false otherwise.

This method can be overridden if you need to customize the way AjaxBehaviors are fired.

Parameters:
context - the request context
ajaxBbehaviorSourceSet - the set of controls with attached AjaxBehaviors
Returns:
true if the page should continue processing, false otherwise
See Also:
fireAjaxBehaviors(org.apache.click.Context, org.apache.click.Control)

fireAjaxBehaviors

protected boolean fireAjaxBehaviors(Context context,
                                    Control source)
Fire the AjaxBehaviors for the given control and return true if the page should continue processing, false otherwise. AjaxBehaviors will only fire if their isAjaxTarget() method returns true.

This method can be overridden if you need to customize the way AjaxBehaviors are fired.

Parameters:
context - the request context
source - the control which attached behaviors should be fired
Returns:
true if the page should continue processing, false otherwise