欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  资讯频道

Apache Wicket 1.5 正式发布

程序员文章站 2022-04-27 14:37:48
...

Apache Wicket 团队正式发布了 Apache Wicket 1.5, 一个基于组件的开源 WEB 框架。Apache Wicket 1.5 经过两年的开发,与之前版本相比,带来无数的改进。

下载地址
-----------------------------
http://www.apache.org/dyn/closer.cgi/wicket/1.5.0

如果使用Maven,可以添加下面的代码到 POM 升级到最新版本:

 

<dependency>
    <groupId>org.apache.wicket</groupId>
    <artifactId>wicket-core</artifactId>
    <version>1.5.0</version>
</dependency>
 

值得注意的是,Wicket 的主 artifact ID 更名为 wicket-core。

你必须升级所有的模块(i.e. wicket, wicket-extensions,
wicket-ioc, wicket-spring, etc) 到1.5.0,在使用最新版本,不要混合使用之前的版本。

值得注意的变更
--------------------

这个发布版本中,Wicket 团队对其内部进行了大量的更新。包括:

- 添加了 HTML5 组件: EmailTextField, NumberTextField, UrlTextField and
   RangeTextField

- 全新的组件内事件机制 (下面会解释)

- servlet API 最低版本为 servlet-api 2.5

- 所有的标准的 validators 继承了 Behavior 以便客户端验证

- 删除 IBehavior,AbstractBehavior 标志为过时,现在你应该直接从 Behavior 继承。

- 简化请求生命周期处理,使其更有扩展性

- URL 集中处理

- Wicket’s rendering 代码大大简化

- 改进了浏览器缓存支持

- ClientSideImageMap 代替了旧的 ImageMap

- Better support for running behind proxies with x-forwarded-for header

- Request cycle listeners  使集成框架到你的 Wicket 应用中变得更加简单

-  一致的命名: 方法名的 Javascript 更名为 JavaScript

- 切换到 HTTPS 很简单,只配置一个新的 root mapper,让 Wicket 能够识别 HTTPS,在页面添加  @RequireHttps

更详细的变更和改进包含在升级指南中.

组件内部事件机制
----------------------

Wicket 1.5 offers a simple, yet flexible, way for component to communicate
with each other in a decoupled manner. The two major interfaces that
facilitate this are:

/**
* Objects that can send events
*/
public interface IEventSource {
     void send(IEventSink sink, Broadcast broadcast, T payload);
}

 
and

/**
* Objects that can receive events
*/
public interface IEventSink
{
    /**
     * Called when an event is sent to this sink
     */
    void onEvent(IEvent&gt; event);
}

 
The classes that implement these interfaces, and can thus participate in the
event mechanism are: Component, RequestCycle, Session, and Application.

The mechanism allows for different event broadcast methods defined here:

/**
* Defines the event broadcast type.
*/
public enum Broadcast {
    BREADTH,
    DEPTH,
    BUBBLE,
    EXACT;
}

 
There is an example in wicket-examples which demonstrates the usage of this.

Applications can register custom event dispatchers in FrameworkSettings; the
dispatchers can be used to build custom event delivery mechanisms. For example
a custom IEventDispatcher mechanism can route events to annotated methods, for
example:

public class MyComponent extends Component {
    @OnEvent
    private void onUserAdded(UserAddedEvent event) {...}
}

 
where UserAddedEvent is the event payload object.

The default Component#onEvent method will be called even if custom dispatchers
are registered.

A default event is raised whenever Wicket begins to create an AJAX response.
The payload of the event is the AjaxRequestTarget used for event. Sample
implementation:

 

// component that always adds itself to the ajax response
public class MyComponent extends Component {
    public void onEvent(IEvent event) {
        if (event.getPayload() instanceof AjaxRequestTarget) {
            ((AjaxRequestTarget)event.getPayload()).add(this);
         }
    }
}