wicket 学习之WicketFIlter中监听初始化
程序员文章站
2022-07-15 15:14:27
...
在WicketFilter初始化的时候,会调用webApplication.initializeComponents()完成组建监听的初始化工作。在wicket1.4.13版本中,实际上掉用了两个类的init方法:
1、org.apache.wicket.Initializer
2、org.apache.wicket.extensions.Initializer
这里以org.apache.wicket.Initializer为例介绍监听的初始化工作。
首先来看看init中的代码:
IBehaviorListener.INTERFACE.register();
IFormSubmitListener.INTERFACE.register();
ILinkListener.INTERFACE.register();
IOnChangeListener.INTERFACE.register();
IRedirectListener.INTERFACE.register();
IResourceListener.INTERFACE.register();
IActivePageBehaviorListener.INTERFACE.register();
以IBehaviorListener.INTERFACE.register();为例,其中INTERFACE维护了org.apache.wicket.RequestListenerInterface对象,register()方法将IBehaviorListener监听器注册到RequestListenerInterface的interfaces中。
监听原理说明:
每个监听接口中都维护了org.apache.wicket.RequestListenerInterface对象,这个对象被设计成静态最终常量,所以在类加载的时候,就被初始化了。API中关于这个类的解释是:Base class for request listener interfaces.这个类在wicket的监听机制中至关重要。为什么重要呢?第一、RequestListenerInterface中维护了一个Map<String, RequestListenerInterface> interfaces,在这个interfaces中保存了所有应用初始化过程中注册的监听器,在wicket的request中会用来完成组建注册监听工作;第二、RequestListenerInterface提供了监听器的回调,这个地方其实是调用了组建上的方法(与监听器同名的方法)(这点很重要,监听程序我认为就是为组建服务的。);第三、RequestListenerInterface中提供了newRequestTarget方法,用来绑定页面,组建,监听。通过RequestListenerInterface,wicket在处理页面请求的时候,完成监听的操作。
下面提供了一些相关的类,供参考:
org.apache.wicket.Initializer :Initializer for components in wicket core library.
org.apache.wicket.IRequestListener :Base interface for all interfaces that listen for requests from the client browser.
org.apache.wicket.RequestListenerInterface :Base class for request listener interfaces.
org.apache.wicket.IRequestTarget :A request target is the base entity that is the subject of a request.
org.apache.wicket.request.target.component.IPageRequestTarget :Request target that denotes a page instance.
org.apache.wicket.request.target.component.PageRequestTargetefault implementation of { IPageRequestTarget}. Target that denotes a page instance.
org.apache.wicket.request.target.component.listener.AbstractListenerInterfaceRequestTarget:
Target that denotes a page instance and a call to a component on that page using an listener interface method.
org.apache.wicket.request.target.component.listener.BehaviorRequestTarget :Target that denotes a page instance and a call to a component on that page using an listener
org.apache.wicket.RequestCycle :Represents the processing of a request.
1、org.apache.wicket.Initializer
2、org.apache.wicket.extensions.Initializer
这里以org.apache.wicket.Initializer为例介绍监听的初始化工作。
首先来看看init中的代码:
IBehaviorListener.INTERFACE.register();
IFormSubmitListener.INTERFACE.register();
ILinkListener.INTERFACE.register();
IOnChangeListener.INTERFACE.register();
IRedirectListener.INTERFACE.register();
IResourceListener.INTERFACE.register();
IActivePageBehaviorListener.INTERFACE.register();
以IBehaviorListener.INTERFACE.register();为例,其中INTERFACE维护了org.apache.wicket.RequestListenerInterface对象,register()方法将IBehaviorListener监听器注册到RequestListenerInterface的interfaces中。
监听原理说明:
每个监听接口中都维护了org.apache.wicket.RequestListenerInterface对象,这个对象被设计成静态最终常量,所以在类加载的时候,就被初始化了。API中关于这个类的解释是:Base class for request listener interfaces.这个类在wicket的监听机制中至关重要。为什么重要呢?第一、RequestListenerInterface中维护了一个Map<String, RequestListenerInterface> interfaces,在这个interfaces中保存了所有应用初始化过程中注册的监听器,在wicket的request中会用来完成组建注册监听工作;第二、RequestListenerInterface提供了监听器的回调,这个地方其实是调用了组建上的方法(与监听器同名的方法)(这点很重要,监听程序我认为就是为组建服务的。);第三、RequestListenerInterface中提供了newRequestTarget方法,用来绑定页面,组建,监听。通过RequestListenerInterface,wicket在处理页面请求的时候,完成监听的操作。
下面提供了一些相关的类,供参考:
org.apache.wicket.Initializer :Initializer for components in wicket core library.
org.apache.wicket.IRequestListener :Base interface for all interfaces that listen for requests from the client browser.
org.apache.wicket.RequestListenerInterface :Base class for request listener interfaces.
org.apache.wicket.IRequestTarget :A request target is the base entity that is the subject of a request.
org.apache.wicket.request.target.component.IPageRequestTarget :Request target that denotes a page instance.
org.apache.wicket.request.target.component.PageRequestTargetefault implementation of { IPageRequestTarget}. Target that denotes a page instance.
org.apache.wicket.request.target.component.listener.AbstractListenerInterfaceRequestTarget:
Target that denotes a page instance and a call to a component on that page using an listener interface method.
org.apache.wicket.request.target.component.listener.BehaviorRequestTarget :Target that denotes a page instance and a call to a component on that page using an listener
org.apache.wicket.RequestCycle :Represents the processing of a request.