|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.ControlRegistry
public class ControlRegistry
Provides a centralized registry where Controls can be registered and interact with the Click runtime.
The primary use of the ControlRegistry is for Controls to register themselves as potential targets of Ajax requests (If a control is an Ajax request target, it's onProcess() method is invoked while other controls are not processed). Registering controls as Ajax targets serves a dual purpose. In addition to being potential Ajax targets, these controls will have all their Behaviors processed by the Click runtime. Thus the ControlRegistry provides the Click runtime with easy access to Controls that want to be processed for Ajax requests. It also provides quick access to Controls that have Behaviors, and particularly AjaxBehaviors that want to handle and respond to Ajax requests.public class AbstractControl implements Control { public void addBehavior(Behavior behavior) { getBehaviors().add(behavior); // Adding a behavior also registers the Control as an Ajax target ControlRegistry.registerAjaxTarget(this); } }
public class MyContainer extends AbstractContainer { public void onInit() { Behavior controlInterceptor = getInterceptor(); ControlRegistry.registerInterceptor(this, controlInterceptor); } private Behavior getInterceptor() { Behavior controlInterceptor = new Behavior() { // This method is invoked before the controls are rendered to the client public void preResponse(Control source) { // Here we can add a CSS class attribute to each child control addCssClassToChildControls(); } // This method is invoked before the HEAD elements are retrieved for each Control public void preRenderHeadElements(Control source) { } // This method is invoked before the Control onDestroy event public void preDestroy(Control source) { } }; return controlInterceptor; } }
Constructor Summary | |
---|---|
ControlRegistry(ConfigService configService)
Construct the ControlRegistry with the given ConfigService. |
Method Summary | |
---|---|
protected void |
errorOccurred(Throwable throwable)
Allow the registry to handle the error that occurred. |
static ControlRegistry |
getThreadLocalRegistry()
Return the thread local ControlRegistry instance. |
static boolean |
hasThreadLocalRegistry()
Returns true if a ControlRegistry instance is available on the current thread, false otherwise. |
static void |
registerAjaxTarget(Control control)
Register the control to be processed by the Click runtime if the control is the Ajax target. |
static void |
registerInterceptor(Control control,
Behavior controlInterceptor)
Register a control event interceptor for the given Control and Behavior. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ControlRegistry(ConfigService configService)
configService
- the click application configuration serviceMethod Detail |
---|
public static ControlRegistry getThreadLocalRegistry()
RuntimeException
- if a ControlRegistry is not available on the
threadpublic static boolean hasThreadLocalRegistry()
getThreadLocalRegistry()
this method can safely be used
and will not throw an exception if a ControlRegistry is not available on
the current thread.
public static void registerAjaxTarget(Control control)
Control.isAjaxTarget(org.apache.click.Context)
method returns true.
Once a target control is identified, Click invokes its
Control.onProcess()
method.
This method serves a dual purpose as all controls registered here
will also have their Behaviors (if any) processed. Processing
Behaviors
means their interceptor methods will be invoked during the request
life cycle, passing the control as the argument.
control
- the control to register as an Ajax targetpublic static void registerInterceptor(Control control, Behavior controlInterceptor)
preRenderHeadElements(Control)
,
preResponse(Control)
and
preDestroy(Control)
.
control
- the interceptor source controlcontrolInterceptor
- the control interceptor to registerprotected void errorOccurred(Throwable throwable)
throwable
- the error which occurred during processing
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |