Wicket 1.5+ in Sakai CLE
Wicket 1.4 to 1.5.9 Migration of Steve Swinsburg example
By David F. Torres
In the pom file
Change the version of the dependency “wicket-spring” to 1.5.9 in the base pom.xml
Change the version of the dependency “wicket” to 1.5.9 in the base pom.xml
Change the type of the dependency “wicket” to “pom” (add the type, previously there was not a type, i.e. it was jar) in the base pom.xml and in the tool/pom.xml
MyApplication.java
Remove
import org.apache.wicket.Request; import org.apache.wicket.RequestCycle; import org.apache.wicket.Response; import org.apache.wicket.protocol.http.WebRequest; import org.apache.wicket.protocol.http.WebRequestCycle; import org.apache.wicket.protocol.http.WebResponse;
Add
import org.apache.wicket.request.IRequestHandler; import org.apache.wicket.request.cycle.IRequestCycleListener; import org.apache.wicket.request.cycle.RequestCycle; import org.apache.wicket.request.Url;
Not sure about I made the right decision here:
Remove:
/** * Throw RuntimeExceptions so they are caught by the Sakai ErrorReportHandler(non-Javadoc) * * @see org.apache.wicket.protocol.http.WebApplication#newRequestCycle(org.apache.wicket.Request, org.apache.wicket.Response) */ @Override public RequestCycle newRequestCycle(Request request, Response response) { return new WebRequestCycle(this, (WebRequest)request, (WebResponse)response) { @Override public Page onRuntimeException(Page page, RuntimeException e) { throw e; } }; }
Add at the end of init():
getRequestCycleListeners().add(new IRequestCycleListener() { public void onBeginRequest() { // optionally do something at the beginning of the request } public void onEndRequest() { // optionally do something at the end of the request } public IRequestHandler onException(RequestCycle cycle, Exception ex) { // optionally do something here when there's an exception // then, return the appropriate IRequestHandler, or "null" // to let another listener handle the exception ex.printStackTrace(); return null; } @Override public void onBeginRequest(RequestCycle arg0) { // TODO Auto-generated method stub } @Override public void onDetach(RequestCycle arg0) { // TODO Auto-generated method stub } @Override public void onEndRequest(RequestCycle arg0) { // TODO Auto-generated method stub } @Override public void onExceptionRequestHandlerResolved( RequestCycle arg0, IRequestHandler arg1, Exception arg2) { // TODO Auto-generated method stub } @Override public void onRequestHandlerExecuted(RequestCycle arg0, IRequestHandler arg1) { // TODO Auto-generated method stub } @Override public void onRequestHandlerResolved(RequestCycle arg0, IRequestHandler arg1) { // TODO Auto-generated method stub } @Override public void onRequestHandlerScheduled(RequestCycle arg0, IRequestHandler arg1) { // TODO Auto-generated method stub } @Override public void onUrlMapped(RequestCycle arg0, IRequestHandler arg1, Url arg2) { // TODO Auto-generated method stub } });
Change
addComponentInstantiationListener(new SpringComponentInjector(this));
for
getComponentInstantiationListeners().add(new SpringComponentInjector(this));
BasePage.java
Change this:
response.renderOnLoadJavascript
for this (note the mayus “S”):
response.renderOnLoadJavaScript
Change this:
response.renderJavascriptReference("/library/js/headscripts.js");
for this:
response.renderJavaScriptReference(new PackageResourceReference("/library/js/headscripts.js"));
Add:
import org.apache.wicket.request.resource.PackageResourceReference;
web.xml
Use this:
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
Add this:
<servlet-mapping> <servlet-name>nameOfYourServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>