[JAVA] What happened to the typical changes in Apache Wicket 8 after all?

Introduction

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.

Model changes

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

Component changes

Use of lambda expressions in Link and Button

** 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 asclick`` blur` are supported ** (prefixed is deprecated in Wicket6) .. It's a good idea to check this all at once when migrating.

At the end

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

What happened to the typical changes in Apache Wicket 8 after all?
What to do when the changes in the Servlet are not reflected
What to do if the changes are not reflected in the jar manifest file
What is object-oriented after all or just one thing to watch out for in programming
What to do when Rails on Docker does not reflect controller changes in the browser
What happened in "Java 8 to Java 11" and how to build an environment
What I did in the version upgrade from Ruby 2.5.2 to 2.7.1
What is object-oriented after all?
What is object-oriented after all?
What to do if the Rails page doesn't appear in Rails tutorial 1.3.2
What I did in the migration from Spring Boot 1.4 series to 2.0 series
What to do if Cloud9 is full in the Rails tutorial
What I did in the migration from Spring Boot 1.5 series to 2.0 series
Don't lose to the unchecked warning! → After all, I couldn't win the unchecked warning ...
What to do if you forget the root password in CentOS7
What to do if the image posted by refile disappears after setting a 404 error page in Rails
What to do if you can't bundle update and bundle install after installing Ruby 3.0.0 in the Rails tutorial
Pass the i18n locale to JavaScript
Apache Camel in the cloud-native era
What to do after Vagrant install
What are the rules in JUnit?
What to do if the background image is not applied after deployment
What to do if the prefix c is not bound in JSP
How to get the value after "_" in Windows batch like Java -version
What is CHECKSTYLE: OFF found in the Java source? Checkstyle to know from
After all I wanted to preview the contents of mysql with Docker ...
What to do about "A server is already running ..." that happened without turning off the rails server in the terminal