Migrate-1.3 has been edited by Jonathan Locke (Apr 05, 2007).

Change summary:

Updated for ISessionFactory and MockWebApplication changes

(View changes)

Content:

Migrating to Wicket 1.3

Getting and building it

http://incubator.apache.org/wicket/building-from-svn.html explains how to obtain and build Wicket 1.3 (1.x).

Snapshots (latest successful builds by our bamboo server) are available at http://wicketstuff.org/maven/repository/

Filter instead of a Servlet

Wicket no longer uses a Servlet as it's main option. In fact, using a servlet filter (WicketFilter) will be
the recommended pattern. Replace code like (in subclasses of WebApplication):

ServletContext sc = getWicketServlet().getServletContext();

with

ServletContext sc = getServletContext();

and

wicket.protocol.http.IWebApplicationFactory#createApplication(wicket.protocol.http.WicketServlet)

is replaced by

wicket.protocol.http.IWebApplicationFactory#createApplication(wicket.protocol.http.WicketFilter)

You can get the servlet context from a filter like this:

filter.getFilterConfig().getServletContext()

The main advantage of working with a filter instead of a servlet is that it is easier to pass through resources, and map your application to the root.


Here's an example of how to configure your application now with a filter in web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
      "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
  <filter>
    <filter-name>MyApplication</filter-name>
    <filter-class>wicket.protocol.http.WicketFilter</filter-class>
    <init-param>
      <param-name>applicationClassName</param-name>
      <param-value>com.myapp.MyApplication</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>MyApplication</filter-name>
    <url-pattern>/app/*</url-pattern>
  </filter-mapping>
</web-app>

API changes

IModel change

IModel#getObject(Component) is replaced by IModel#getObject() and
IModel#setObject(Component, Object) is replaced by IModel#setObject(Object)

Here are some regex replacement that are helpful:

s/public\s+Object\s+getObject\s*\(\s*(final)*\s*(wicket.)?Component\s+\w+\s*\)/public Object getObject()

and

s/public\s+void\s+setObject\s*\(\s*(final)*\s*(wicket.)?Component\s+\w+,\s*(final)*\s*Object\s+(\w+)\s*\)/public void setObject(Object \2)

You're probably best of doing the calls to get/setObject you did on models yourself manually.

Some miscellaneous abstract model classes have been removed as they did not provide much value. Here is a simple migration mapping if you extended one of the removed classes in your code:

AbstractModel->Model
AbstractDetachableModel->LoadableDetachableModel

wicket.extensions.model.AbstractCheckBoxModel now has select/ unselect instead of setSelected(Component, boolean), and isSelected doesn't have the Component parameter anymore.

TODO explain how to use the new models like IAsignementAwareModel, IInheritableModel and IWrapModel

Validation Changes

Form component level validation has been decoupled from FormComponent so that validators can be reused outside wicket. The new API can be found in wicket.validation package, with the validator implementations in wicket.validation.validator. From the point of view of validator development not much has changed if you extended the AbstractValidator; if you however implemented the IValidator interface directly you will need to use the new API, namely error reporting via ValidationError instead of FormComponent.error(List,Map). Errors with messages fully constructed inside the validator can still be reported using FormComponent.error(String).

WicketTester and MockWebApplication

MockWebApplication and WicketTester are no longer derived from WebApplication which allows to use
"MyApplication" for testing as well instead of copy & paste the MyApps code.

MockWebApplication and therefore WicketTester both consistently use factory methods to create requests and responses now. This allows for custom request and response subclasses to be used in testing.

ISessionFactory

Session factory interface now takes a response object to permit things like initializing a cookie in a new session during construction (for example, by a unit test):

Session newSession(Request request, Response response);

Repeaters

The repeaters package has moved from wicket-extensions into core. The package name has been changed from wicket.extensions.markup.html.repeater to wicket.markup.repeater. Notice that only DataView and backing classes have moved, the higher level components such as the DataTable are still in wicket-extensions. Also notice that the names of classes have not changed so it should be a simple matter of ctrl-shift-o in your eclipse project to relink to the new classes.

DatePicker

The DatePicker component has been removed from the wicket-extensions package, as it conflicts with the Apache license.

There are two options for migration:

  • A drop-in replacement (same component) provided by Wicket Stuff.
  • A new date picker based on the Yahoo UI library, which is available in the wicket-datetime package. Find it under wicket.extensions.yui.calendar.DateField (see also DateTimeField and CalendarPopup for other useful components).

Portlets JSR-168

The portlet support has been moved to wicket-stuff, as we couldn't support it inside the Wicket core. If you need portlet support please checkout the code from wicket-stuff and include that instead. The portlet examples also have been moved to Wicket stuff.

ISessionStore

ISessionStore had the following changes:
String getSessionId(Request request); -> String getSessionId(Request request, boolean create);
+ void onBeginRequest(Request request);
+ void onEndRequest(Request request);
+ PageMap createPageMap(String name, Session session);
By default, the creation of lasting sessions is deferred until actually needed. As long no lasting session is yet created and users are accessing stateless pages, a temporary session object is used for the current request.

HttpSessionStore and all subclasses now require the application which they are created for to be passed in in the constructor.

Button

AjaxSubmitButton and AjaxSubmitLink now extend Button and Button extends IFormSubmittingComponent. As a result of this, method onSubmit changed from protected to public

IHeaderContributor

void renderHead(final Response response); -> void renderHead(final IHeaderResponse response);
This resulted in a couple of cascading changes, like methods onRenderHeadContribution and onRenderHeadInitContribution not being used anymore. Note that the filtering of duplicate contributions is now part of IHeaderResponse.
A common fix is this:

protected void onRenderHeadInitContribution(Response response) {
    writeJsReference(response, AUTOCOMPLETE_JS);
  }

should be converted to:

public void renderHead(IHeaderResponse response) {
    super.renderHead(response);
    response.renderJavascriptReference(AUTOCOMPLETE_JS);
  }

or for instance code like

protected String getImplementationId() {
  return "ArchiveActions";
}

protected void onRenderHeadContribution(Response response) {
  if (!isComplete()) {
    response.write("<script>");
    response.write(getCallbackScript().toString());
    response.write("</script>");
  }
}

would be rewritten like

public void renderHead(IHeaderResponse response) {
  if (!isComplete()) {
    response.renderJavascript(getCallbackScript(), "ArchiveActions");
  }
}

ISessionFactory

Session newSession() -> Session newSession(Request)

FormComponent.IVisitor

Things have been refactored into interfaces here. If you previously implemented this directly, extend FormComponent.AbstractVisitor instead, and rename your formComponent() implementation to onFormComponent().

ClientProperties

wicket.protocol.http.ClientProperties was taken from the Echo2 project that uses a license which is incompatible with ASL2. It has therefore been rewritten and the usage of it has also changed.

Instead of:

WebClientInfo clientInfo = (WebClientInfo) Session.get().getClientInfo();
ClientProperties properties = clientInfo.getProperties();

// Before constants where used to get properties
System.out.println(properties.get(ClientProperties.BROWSER_INTERNET_EXPLORER));

You now say:

WebClientInfo clientInfo = (WebClientInfo) Session.get().getClientInfo();
ClientProperties properties = clientInfo.getProperties();

// Now you use a property with that name instead
System.out.println(properties.isBrowserInternetExplorer());

Application settings

Application#getSettings is now private (so you can't call nor override that anymore), and the getXxxSettings are now overridable in case you want to do fancy stuff like creating a session-dependent settings object. Methods getApplicationPages and getApplicationSettings from component are now removed in favor of the getXxxSettings methods in Application.

Setting get/setDefaultLocale is removed and is does not have a replacement.

Custom Sessions

Session's constructor signature is now:

protected Session(Application application, Request request)

The locale is not set right after construction in WebApplication, but rather in the constructor using the passed in request. You can now 'fix' the session's locale by setting it in it's constructor.

Custom resource loading

In Wicket 1.2 you could override method newMarkupResourceStream from MarkupContainer to provide a custom resource stream for loading the component's markup. The new way of letting markup containers provide custom markup is to let them implement interface IMarkupResourceStreamProvider and implement it's method getMarkupResourceStream. Additionally, a new feature is that you can provide your own markup cache key, which is used in the MarkupCache class. The only real use case for that is to let a markup container return a cache key that is null, in which case the resource won't be cached, causing Wicket to get call getMarkupResourceStream everytime the component's markup is requested. A use case for that is when you have dynamic markup (e.g. from a database) that is request/ session dependent. To achieve this, let your markup container also implement IMarkupCacheKeyProvider and let method getCacheKey return null.

Test serialization setting removed

The setting IDebugSettings#SerializeSessionAttributes is removed. Instead you can use the SecondLevelCacheSessionStore, which serialized (old) pages to a second level cache (user.tmp by default). SecondLevelCacheSessionStore will (probably) be the default configured session store, but you can configure it yourself by doing in your application:

/**
 * @see wicket.Application#newSessionStore()
 */
protected ISessionStore newSessionStore() {
  return new SecondLevelCacheSessionStore(new FilePageStore());
}

Also, you can use

wicket.util.Objects#checkSerializable(Object)

to check for non-serializable objects yourself. You could do this for instance in a custom session store implementation.

Palette component in wicket-extensions now has default CSS.

You can revert this back to 1.2.x behaviour by overriding getCSS() and returning null.

IRequestCycleProcessor got simplified

The interface itself didn't change, but we've pulled out a redundant layer of indirection that was confusing more than it helped matters. There is now a simply class hierarchy, and WebRequestCycleProcessor is the class you'll most likely need. See for more info the JIRA issue at http://issues.apache.org/jira/browse/WICKET-287

Removed IPageSettings#maxPageVersions

The IPageSettings#maxPageVersions is removed from 1.3. The setting is not relevant for SecondLevelCacheSessionStore (the new default session store implementation), which uses SecondLevelCachePageVersionManager. If you use HttpSessionManager or a custom one together with UndoPageVersionManager, you can provide max page versions number as a UndoPageVersionManager's constructor argument. By default this is now 20 (opposed to max int which it was earlier). See also http://issues.apache.org/jira/browse/WICKET-266

Simlified HeaderContributor

Removed instance methods of HeaderContributor and now just keep one IHeaderContributor instance for clarity and efficiency.

Removed feedback messages from page

All feedback messages are now maintained by the session. See https://issues.apache.org/jira/browse/WICKET-442

New Features

wicket:enclosure tag

see http://www.nabble.com/two-small-feature-ideas-tf2107229.html#a5835972

Reply via email to