Migration to Wicket 1.5Page edited by Martin GrigorovChanges (1)
Full ContentMigrating to Wicket 1.5
Environment
Upgraded to JUNIT4We changed the root pom.xml to use junit4 (4.7) Removed deprecated method, class and interface definitionsIn order to keep the code clean, we removed all methods, classes and interfaces which were marked deprecated in Wicket 1.4. Before migrating to Wicket 1.5 you should replace all deprecated invocations. Removed FormComponent.setPersistence()WICKET-2213: At the very beginning of Wicket we introduced FormComponent.setPersistence() with the idea to make creating Login panels very easy. Basically Wicket would deal with the Cookie handling for the login details. Now some years later it is evident that this feature is not very useful:
So we removed that feature and introduced IAuthenticationStrategy. A default implementation has been provided and the examples have been updated. As usual it gets registered with ISecuritySettings. In case you want to implement your own IAuthenticationStrategy, a utility class org.apache.wicket.util.cookies.CookieUtils has been added. Removed IComponentBorderThe interface has been removed since IBehavior can do exactly the same. MarkupComponentBorder has been migrated, which means you can add associated markup to the behavior. Markup which will surround the behavior's component. Component.getStyle() implementation changedgetStyle() used to return Component.getVariation() + "_" + style. That eventually caused issue such as mentioned in WICKET-2298. We changed that to getStyle() now returning style only which as a consequence required us to change all resource related APIs to add variation. To migrate your code you might either provide component.getVariation() or null where not relevant. Removed magic from Border ComponentWe had several issues with Border such as WICKET-2494 and the fact that all over core you could find code such as "if (comp instanceof Border) {}" . That is now all fixed, though at a (low) price. Because the magic is now gone, we think it is even clearer than is was before. The difference is you have to tell Border where to add the child component. Whether it will be added to <wicket:border>..</wicket:border> which is called the "border", or <span wicket:id="myBorder">..</span> which called the "border body". And because the body can be wrapped by a container such as a Form, you need to add (move) the body to the wrapper component via wrapper.add(getBodyContainer()) if needed. By doing so you create a clean component hierarchy with no more magic and ambiguities and transparent resolvers. border.addToBorder() and border.addToBorderBody() can be used to explicitly tell where to add the child. border.add() will add it the body. see Border javadoc as well Component renderingWe used to have different entry points to render a Page, a Component for a web request and a Component for an AJAX request. That is history. Whenever you want to render a component, simply call component.render(). You may recall that Component.render(MarkupStream) already existed and thus in most cases (e.g. IComponentResolvers implementations) you simply need to remove the markupStream parameter. The markup fragment which is still needed to render a Component is retrieved via Component.getMarkup(). Most components will ask their parent container to find it via MarkupContainer.getMarkup(Component child). IMarkupFragment is a new concept introduced. A markup fragment is what is says: a fragment of markup taken from a larger resource (file). Please see the javadoc on when it is better to subclass getMarkup() and when getMarkup(Component). Component.getMarkup() successfully returns a result as soon as it is connected (add) to a parent with an associated markup resource (file). Note that this usually is not in the component constructor, since the component itself will not yet been added to its parent. You may recall that until now you very carefully had to forward the markup stream to the next suitable position. That has been simplified as well. Every component will use its own markup stream and the parent container is responsible to position it while rendering its child components. On the same topic: onRender(MarkupStream) has been changed to onRender(); no more MarkupStream. You can get for every component once you called render() via getMarkupStream(). UTF-8 encoded property filesIf you are using Java 6 or newer, than Wicket will be configured to use java.util.Properties#load(Reader(in, "utf-8")) for files with "*.utf8.properties" extension. TabbedPanel
MarkupContainer.isTransparentResolver() removedWe removed MarkupContainer.isTransparentResolver() in favor of the more general IComponentResolver. To make transition easy, we provide a TransparentWebMarkupContainer. In cases where TransparentWebMarkupContainer doesn't work for you, please see TransparentWebMarkupContainer on how to achieve the same effect with your component. Different than MarkupContainer.isTransparentResolver() where the component's id wasn't needed in the component's path, with IComponentResolver it must be included. Imagine you used to have a transparent container <body wicket:id="myBody">, you were able to access a label from the Page just by "myLabel". With the change, you must use "myBody:myLabel". IComponentResolver.resolve API has changedUntil now, with IComponentResolver.resolve() is was your responsibility to render the component. You returned true, if the component was found and rendered. That was because we had different means to render the component and wicket itself was not able to judge which one to use. That has changed and thus we were able to change the IComponentResolver.resolve API. With the revised API, you simply return the resolved component and wicket core knows what to do with it. It made Wicket's internal code simpler and hopefully yours as well. Wicket-IOC changesInjectorHolder.getInjector().inject(Object object) is replaced with org.apache.wicket.injection.Injector.get().inject(Object object). Wicket-Guice's InjectionFlagCachingGuiceComponentInjector is removed. The replacement is GuiceComponentInjector. The caching mechanism that InjectionFlagCachingGuiceComponentInjector provided is moved to org.apache.wicket.injection.Injector so that the caching is re-used for both Wicket-Spring and Wicket-Guice. VisitorsVisitors have been cleaned up. Dependency on magic return values defined in Component#IVisitor have been replaced with a Component#IVisit object that allows the visitor to control the flow of the traversal. formComponent.visitChildren(Radio.class, new IVisitor<Component>() { public /*[1]*/ Object component(Component component /*[2]*/) { if (value.equals(component.getDefaultModelObject())) { addFormComponentValue(formComponent,((Radio<?>)component).getValue()); return STOP_TRAVERSAL; /*[3]*/ } return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER; /*[4]*/ } }); formComponent.visitChildren(Radio.class, new IVisitor<Component, Void>() { public void /*[1]*/ component(final Component component, final IVisit<Void> visit /*[2]*/) { if (value.equals(component.getDefaultModelObject())) { addFormComponentValue(formComponent,((Radio<?>)component).getValue()); visit.stop(); /*[3]*/ } else { visit.dontGoDeeper(); /*[4]*/ } } }); [1] The new style visitor no longer returns a value, instead the value can be returned using visit.stop(value)
Change Notification Preferences
View Online
|
View Changes
|
Add Comment
|
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence
- [CONF] Apache Wicket > Migration to Wicket 1.5 confluence