Wicket developers have worked to make migration from 7.x to 8.x as smooth as possible. Most of the time the required changes to migrate to the new version will be spotted by the Java compiler producing a compile error. There are however some important changes (in the API or in the framework's behavior) that won't result in a compilation problem but which are nonetheless very important and could lead to undesired changes in your application's behavior. The following is a list of such changes. You are strongly invited to review them as part of the migration process:
if (RequestCycle.get().find(AjaxRequestTarget.class) == null) { // executed for non-ajax-request in Wicket 7 // never executed in Wicket 8 ... } |
See Migration to Wicket 8.0#WICKET-6189 for more details
@Override public void init() { setHeaderResponseDecorator(new JavaScriptToBodyCustomResponseDecorator("footer")); } |
This code doesn't work anymore. See Migration to Wicket 8.0#WICKET-6498 for more details
Ajax multipart uploads (e.g. FileUploadField in Ajax submits) require https://developer.mozilla.org/en-US/docs/Web/API/FormData , for Internet Explorer that implies version 10 or higher.
Because of license issues all json.org classes in that package have been removed and open-json (https://github.com/tdunning/open-json) is used as new dependency. Basic functionalities can be reused by only changing the imports from org.apache.wicket.ajax.json.* to org.json.*, org.apache.wicket.ajax.json.JsonFunction has been renamed to org.apache.wicket.ajax.json.JSONFunction and some classes are deleted without any replacements (example: org.json.HTTP)
Replace it with standard Java 8 java.util.function.Supplier<T> which is virtually identical.
Replace IContextProvider<T, C> with standard Java 8 java.util.function.Function<C, T> which is virtually identical.
As a consequence IPageManagerProvider, IPageRendererProvider and IRequestCycleProvider now override #apply() method instead of #get().
Tests based on HtmlDocumentValidator are very fragile. They start to fail as soon as there is a single character change somewhere in the page markup.
We believe that there are very few users of this API. It is recommended to use TagTester and WicketTestCase#executeTest() instead.
Use an anonymous instance of IModel instead. Since Wicket 8.0 IModel doesn't require providing implementation of #setObject(Object) method.
ConcurrentHashMap.newKeySet() should be used instead
All specialization classes return their type.
For consistency with other components and the new lambda support, the submitted form is no longer passed as argument to callback methods (e.g. #onSubmit(), #onClick()) of AjaxButton, AjaxSubmitLink and AjaxFallbackButton. You can call #getForm() instead.
Code calling RequestCycle#find(Class<T>) has to check whether a matching IRequestHandler is found. This is now enforced by returning an Optional<T>:
getComponent().getRequestCycle().find(AjaxRequestTarget.class).ifPresent(target -> target.add(this)); |
During migration you should check your old code for places where the AjaxRequestCycle (now an Optional<AjaxRequestTarget>) is compared with null: |
if (cycle.find(AjaxRequestTarget.class) == null) { // this is *never* executed since #find() always returns an Optional } if (cycle.find(AjaxRequestTarget.class) != null) { // this is *always* executed since #find() always returns an Optional } |
All AjaxFallback** components and the containers which use internally AjaxFallback** components, like AjaxTabbedPanel, RatingPanel and TableTree, have been reworked to pass Optional<AjaxRequestTarget> instead of just AjaxRequestTarget to their onXyz() callback methods. This way the application developer should not forget to check that the AjaxRequestTarget is not null.
AbstractChoice#getChoices() has been made final. If the application needs to provide different choices for each render then it should override AbstractChoice#getChoicesModel() instead. The application code would be almost the same as before, it will just need to wrap the final List result in an IModel, most probably ListModel.
RequestListenerInterface was removed:
A Component or Behavior can now implement IRequestListener once only, thus removing the need to include an identifier (e.g. "ILinkListener") in the URL.
If you implemented IResourceListener previously, you have to override IRequestListener#rendersPage() now to return false.
Change notification was moved from CheckBox, DropDownChoice, RadioChoice, CheckGroup/Check and RadioGroup/Radio into a new behavior FormComponentUpdatingBehavior.
Instead of subclasses the component, this behavior can now be added to the component:
// Wicket 7.x new CheckBox("id", model) { protected boolean wantOnSelectionChangedNotifications() { return true; } protected void onSelectionChanged(Boolean newSelection) { // do something, page will be rerendered; } }; // Wicket 8.x new CheckBox("id", model) .add(new FormComponentUpdatingBehavior() { protected void onUpdate() { // do something, page will be rerendered; } protected void onError(RuntimeException ex) { super.onError(ex); } }); |
As with AjaxFormComponentUpdatingBehavior any error during processing of the form component can now be handled in #onError().
Renderers (IChoiceRendere, IOptionRenderer and IAutoCompleteRenderer now take part in detachment as other Wicket concepts like components and models. The owning component is responsible to detach it.
Before WICKET-6498 users used to create a custom implementation of IHeaderResponseDecorator to place JavaScript items inside page body:
@Override public void init() { setHeaderResponseDecorator(new JavaScriptToBodyCustomResponseDecorator("footer")); } |
Each Application has an IHeaderResponseDecorator now by default, which decorates header responses with a ResourceAggregator. Projects using their own response decoration (e.g. via JavaScriptFilteredIntoFooterHeaderResponse) have to make sure, that each response is explicitly decorated with a ResourceAggregator too, since Application no longer does it implicitly, e.g.:
setHeaderResponseDecorator(response -> { return new ResourceAggregator(new JavaScriptFilteredIntoFooterHeaderResponse(response, "footer")); }); |
Component verifies that subclasses overriding #onConfigure() delegate to their parent implementation now, as it does for other callbacks like #onInitialize(). Make sure that you call super.onConfigure() if you haven't done so already,
FormComponent#clearInput() has been made non-final, so that now containers like FormComponentPanel could override this method and call #clearInput() on its children of type FormComponent.
By using org.apache.wicket.resource.DynamicJQueryResourceReference Wicket will contribute jQuery ver. 2.x for modern browsers and ver. 1.x when the request is done by Internet Explorer older than ver. 9.
The old behavior of #signOut() didn't bring much value and caused confusion to some users. Now it is just an alias of Session#invalidate().
If this setting is enabled then a page could not be requested via /wicket/bookmarkable/com.example.PageName. A page has to be explicitly mounted at MyApplication#init() to be able to request it.
WicketObjects#cloneObject() and #sizeof() now create a new instance of JavaSerializer to clone or take the size of an object respectively.
If the configured ISerializer in the IFrameworkSettings is not an instance of JavaSerializer then it is used as is!
StatelessChecker now provides an overrideable method named #fail() that accepts an instance of StatelessCheckFailureException. This method is being called
Using FeedbackCollector(Component) constructor will collect only the messages related to the passed Component but not any Session scoped feedback messages.
Ajax multipart requests are now done via Ajax like their non-multipart counterparts. Therefore onsubmit() is no longer called via JS on the form by default.
AjaxFormSubmitBehavior offers an alternative via overriding and returning true from #shouldTriggerJavaScriptSubmitEvent(), which will trigger an 'submit' event on the form regardless of multipart or normal Ajax requests.
Since Wicket 8.x requires Servlet 3.1 the modules for native websocket support for Jetty 7.x/9.0.x have been dropped.
Users are advised to use wicket-native-websocket-javax module with Jetty 9.2+, Apache Tomcat 7/8, JBoss WildFly.
The experimental integration for Atmosphere has been removed because of stability issues.
Users are advised to use wicket-native-websocket-javax module with Jetty 9.2+, Apache Tomcat 7/8, JBoss WildFly.
Several deprecated classes where removed:
With WICKET-6503 several internal methods were removed from the Component API (i.e. those marked with "THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT!"). #onAfteRenderChildren() was removed too, if you had overriden it use #afterRender() instead.
#renderPart() is now the main entrance to render a single component - the caller has to make sure that #beforeRender() has been called on it before.
WICKET-6544 deprecates Wicket's user agent detection, as the API and implementation was not sufficient for modern browsers - it will be removed in Wicket 9.
Users are encouraged to utilize https://github.com/nielsbasjes/yauaa
The helper method for casting of models was moved from Model to IModel#of(IModel<?>).
For convenience IModel class provides a do-nothing implementation of IDetachable#detach() method, so custom implementations are not required to implement it when not needed.
For convenience IRequestHandler class provides a do-nothing implementation of its #detach() method, so custom implementations are not required to implement it when not needed.
For access to the response, the request and its parameters now ResourceStreamResource#getResourceStream() receives an instance of org.apache.wicket.request.resource.IResource.Attributes.
java.util.function.Consumer and other classes are not serializable and this makes them unusable in stateful Wicket pages. For this reason Wicket provides org.apache.wicket.model.lambda.WicketSupplier, org.apache.wicket.model.lambda.WicketConsumer, org.apache.wicket.model.lambda.WicketFunction and org.apache.wicket.model.lambda.WicketBiFunction. Those interfaces should be used in method signatures where Java 8 lambdas or method references could be used. At the call site there is nothing specific to be done, i.e. just use lambdas and method references without any casting.
Wicket provides a new implementation of IModel which uses Java 8 consumers and suppliers, i.e. may be used with lambda or method references
org.apache.wicket.model.LambdaModel
Person person = ...; IModel<String> personNameModel = new LambdaModel<>( () -> person.getName(), (name) -> person.setName(name)); |
org.apache.wicket.model.LambdaModel with method references
Person person = ...; IModel<String> personNameModel = LambdaModel.of(person::getName, person::setName); |
org.apache.wicket.model.LambdaModel can be created with a target model too - note the upper-case 'P' for the function references:
IModel<Person> person = ...; IModel<String> personNameModel = LambdaModel.of(person, Person::getName, Person::getName); |
IGenericComponent uses Java 8 default methods to implement #setModel(IModel<T>), #getModel(), #setModelObject(T) and #getModelObject() by delegating to the respective get/setDefaultModel[Object] methods.
This way it could be easily used by any Component by just implementing it.
IModel provides default implementations of #detach() (do nothing) and #setObject(T) (throws UnsupportedOperationException), so it is possible to use it as a functional interface.
new Link<String>("", () -> "abc") { @Override public void onClick() { // ... } }; Label label = new Label("id", person::getName); // the method reference is actually IModel<String> |
columns.add(new LambdaColumn<Contact, String>(new Model<>("Last Name"), "lastName", Contact::getLastName) |
For convenience IColumn class provides an implementation of #isSortable() method that uses #getSortProperty() to decide. Just like AbstractColumn did until Wicket 7.
New methods have been added to help manipulating the tables' headers: IColumn#getHeaderColspan() and IColumn#getHeaderRowSpan(). Both of them return 1, so the header cells do not span by default.
IRequestCycleListeners are now notified of the execution of all IRequestHandlers, including those scheduled by other handlers, those replacing other handlers, and any handler executed due to an exception:
RequestHandlerStack is now renamed to RequestHandlerExecutor.
With this method now an application may explicitly expire pages selectively.
By overriding org.apache.wicket.request.mapper.AbstractMapper#resolveLocale(), e.g. like in the test case, the application may use the session/request's locale while parsing numbers with PageParameters#get("someNumericParameter").toInt().
All libraries on which Wicket modules depend are updated to their latest stable versions.
The most notable ones are: