I've been away from product development and maintenance for about a year, and I'm happy to say that Apache Wicket 8.0.0 has been released 22 / wicket-8-released.html).
Article on typical changes around 8.0.0_M3 was written in winter 2016 and released in May 2018, so this time It seems that it was a long run-up period.
In this article, I will summarize ** the parts of the article around M3 that changed at the time of official release **. I will link to the M3 article for the parts that have not changed. It does not cover all changes and the migration guide.
There seems to be no major change from the M3 article.
--LambdaModel
can be used
--If you pass a Lambda expression or method reference to the component, it will wrap it in the Model.
--You can pass a Lambda expression or method reference to the ʻof method of
LoadableDetachacbleModel --ʻAbstractReadOnlyModel
is deprecated (use ʻIModel # getModel`)
Past articles: https://qiita.com/gishi_yama/items/59fae7f2a56df31c5749#model changes
** Support with the standard library has been discontinued **.
For example
The way it was done when I was in M3
Link<Void> foo = Link.onClick("toHogePage", (l) -> setResponsePage(new toHogePage(model)));
** Lambda expression & factory-like writing like ** can not be done only by upgrading to 8.
This was decided at the time of the release of M5, it has an irreversible effect (it can be added later but can not be stopped later), and it is a good idea to lambdaize the method that can be overridden for all components, Ajax It seems that the reason is that it is difficult to retain the meta information of the component.
However, it is not the case that Lambda expressions can no longer be used in components.
Wicketstuff Lambda Components
Wicket organizes extension components etc. into a project called WicketStuff, which can be used by adding a library. Instead of the above, we now have a component factory where you can use Lambda expressions.
pom.xml
<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>wicketstuff-lambda-components</artifactId>
<version>8.0.0</version>
</dependency>
Add the library with
ComponentFactory example
//Up to Wicket 7------------
Link<Void> link = new Link<Void>("toFooPage") {
private static final long serialVersionUID = 3391006051307639762L;
@Override
public void onClick() {
//Various processing
setResponsePage(new FooPage(model));
}
};
//Factory example of Wicket 8 & Wicketstuff Lambda Components------------
//The second argument, link, is a reference to the declared Link instance itself.
Link<Void> link = ComponentFactory.link("toFooPage", (link) -> {
//Various processing
setResponsePage(new FooPage(model));
});
//If you just move the page, you can make it one line
Link<Void> link = ComponentFactory.link("toFooPage", (link) -> setResponsePage(new FooPage(model)));
You can use factory methods like this.
If you statically import ComponentFactory
,
Link<Void> foo = link("toListPage", (link) -> setResponsePage(new FooPage(model)));
You can write that, and it will be cleaner.
Components that have a factory method in ComponentFactory
There are 5 types. I personally wanted Button
, but I don't have it ... (maybe I should send a pull request).
Behavior
There seems to be no major change from the M3 article. This can be declared using a Lambda expression, as it was originally.
Past articles: https://qiita.com/gishi_yama/items/59fae7f2a56df31c5749#behavior
Also, from Wicket8, pass it to ʻAjaxEventBehavioretc. ** Only JS event names that do not have an on prefix such as
click`` blur` are supported ** (prefixed is deprecated in Wicket6) .. It's a good idea to check this all at once when migrating.
I personally paid attention to how much Lambda would come in, but it was released in a way that avoided drastic changes. Since the basics remain the same, upgrading may be easier from a migration and maintenance perspective.
There are other changes, so if you are upgrading, please refer to the migration guide. (I would like to add it if there is a case that I am addicted to maintenance)
The code example after reflecting the contents of this article is here.
Recommended Posts