Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>NOTE: A new class has been added to Wicket 1.5.2 for backwards compatibility with 1.4 style URL encoding. It's called UrlPathPageParametersEncoder - use that if you're migrating a wicket 1.4 app to 1.5 and you have bookmarkable page links of the style:</p> <p>www.mysite.com/name1/value1/name2/value2</p> <p>We had the exact same issue when migrating from 1.4 to 1.5. Any 1.4 app that has been live for a while would likely have a collection of links pointing to it from external sites on the web. You <em>really</em> want the Wicket 1.5 version of your app to be able to handle these existing hybrid links without generating an error.</p> <p>When migrating to 1.5, without a 1.4 compatible IPageParametersEncoder implementation, you need to include the full parameter specification in every mount if you want to avoid making changes to each individual Page class that reads parameters. The implementation below means that is no longer necessary. Just mount the page as livid suggests above.</p> <p>I'm submitting this .java file as a patch to the Wicket devs - they may include it in Wicket in the future to make it easy to implement backwards compatible URL parameter encoding for other 1.4 migrators.</p> <p>I took luniv's sample code above and made a few small changes to get it compiling/working. The following should work as a parameter encoder to provide 1.4.x style parameter encoding in 1.5.</p> <pre><code> package org.apache.wicket.request.mapper.parameter; import java.lang.*; import org.apache.wicket.request.mapper.parameter.IPageParametersEncoder; import java.util.Iterator; import org.apache.wicket.request.Request; import org.apache.wicket.request.Url; import org.apache.wicket.request.mapper.parameter.PageParameters; public class HybridPageParametersEncoder implements IPageParametersEncoder { /** * Encodes a URL in the form: * * /mountpoint/paramName1/paramValue1/paramName2/paramValue2 * * (i.e. a URL using the pre wicket 1.5 Hybrid URL strategy) */ public Url encodePageParameters(PageParameters pageParameters) { Url url = new Url(); for (PageParameters.NamedPair pair : pageParameters.getAllNamed()) { url.getSegments().add(pair.getKey()); url.getSegments().add(pair.getValue()); } return url; } /** * Decodes a URL in the form: * * /mountpoint/paramName1/paramValue1/paramName2/paramValue2 * * (i.e. a URL using the pre wicket 1.5 Hybrid URL strategy) */ public PageParameters decodePageParameters(Request request) { PageParameters parameters = new PageParameters(); int i = 0; for (Iterator&lt;String&gt; segment = request.getUrl().getSegments().iterator(); segment.hasNext(); ) { String key = segment.next(); String value = segment.next(); parameters.add(key, value); } return parameters.isEmpty() ? null : parameters; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload