wicket-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Wicket > Wicket and localized URLs
Date Sat, 07 Nov 2009 16:27:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=WICKET&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/WICKET/Wicket+and+localized+URLs">Wicket
and localized URLs</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~jo@umask.net">Jo
Geraerts</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h3><a name="WicketandlocalizedURLs-Description"></a>Description</h3>
<p>If you have application which require encoding of locale in pages URLs, for instance:
<br/>
www.domain.com/uk/home <br/>
www.domain.com/nl/home </p>

<h4><a name="WicketandlocalizedURLs-RequestDecorator"></a>RequestDecorator</h4>
<p>Simple decorator class for a Request object, used in LocaleUrlCodingStrategyDecorator
to strip the locale from the original<br/>
url</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>RequestDecorator.java</b></div><div
class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">import</span> org.apache.wicket.Request;
<span class="code-keyword">import</span> org.apache.wicket.Page;

<span class="code-keyword">import</span> java.util.Locale;
<span class="code-keyword">import</span> java.util.Map;

<span class="code-keyword">public</span> class RequestDecorator <span class="code-keyword">extends</span>
Request {


    /**
     * Decorated request.
     */
    <span class="code-keyword">private</span> <span class="code-keyword">final</span>
Request request;


    /**
     * Constructor.
     *
     * @param request to decorate.
     */
    <span class="code-keyword">public</span> RequestDecorator(<span class="code-keyword">final</span>
Request request) {
        <span class="code-keyword">if</span> (request == <span class="code-keyword">null</span>)
{
            <span class="code-keyword">throw</span> <span class="code-keyword">new</span>
IllegalArgumentException(<span class="code-quote">"Decorated Request cannot be NULL!"</span>);
        }
        <span class="code-keyword">this</span>.request = request;
    }


    /**
     * {@inheritDoc}
     */
    @Override
    <span class="code-keyword">public</span> Locale getLocale() {
        <span class="code-keyword">return</span> request.getLocale();
    }


    /**
     * {@inheritDoc}
     */
    @Override
    <span class="code-keyword">public</span> <span class="code-object">String</span>
getParameter(<span class="code-keyword">final</span> <span class="code-object">String</span>
key) {
        <span class="code-keyword">return</span> request.getParameter(key);
    }


    /**
     * {@inheritDoc}
     */
    @Override
    <span class="code-keyword">public</span> Map&lt;<span class="code-object">String</span>,
<span class="code-object">String</span>[]&gt; getParameterMap() {
        <span class="code-keyword">return</span> request.getParameterMap();
    }


    /**
     * {@inheritDoc}
     */
    @Override
    <span class="code-keyword">public</span> <span class="code-object">String</span>[]
getParameters(<span class="code-keyword">final</span> <span class="code-object">String</span>
key) {
        <span class="code-keyword">return</span> request.getParameters(key);
    }


    /**
     * {@inheritDoc}
     */
    @Override
    <span class="code-keyword">public</span> <span class="code-object">String</span>
getPath() {
        <span class="code-keyword">return</span> request.getPath();
    }


    /**
     * {@inheritDoc}
     */
    @Override
    <span class="code-keyword">public</span> <span class="code-object">String</span>
getQueryString() {
        <span class="code-keyword">return</span> request.getQueryString();
    }


    /**
     * {@inheritDoc}
     */
    @Override
    <span class="code-keyword">public</span> <span class="code-object">String</span>
getRelativePathPrefixToContextRoot() {
        <span class="code-keyword">return</span> request.getRelativePathPrefixToContextRoot();
    }


    /**
     * {@inheritDoc}
     */
    @Override
    <span class="code-keyword">public</span> <span class="code-object">String</span>
getRelativePathPrefixToWicketHandler() {
        <span class="code-keyword">return</span> request.getRelativePathPrefixToWicketHandler();
    }


    /**
     * {@inheritDoc}
     */
    @Override
    <span class="code-keyword">public</span> <span class="code-object">String</span>
getURL() {
        <span class="code-keyword">return</span> request.getURL();
    }

    @Override
    <span class="code-keyword">public</span> <span class="code-object">String</span>
decodeURL(<span class="code-object">String</span> url) {
        <span class="code-keyword">return</span> request.decodeURL(url);
    }

    @Override
    <span class="code-keyword">public</span> Page getPage() {
        <span class="code-keyword">return</span> request.getPage(); 
    }

    @Override
    <span class="code-keyword">public</span> void setPage(Page page) {
        <span class="code-keyword">super</span>.setPage(page); 
    }

    @Override
    <span class="code-keyword">public</span> <span class="code-object">String</span>
getRelativeURL() {
        <span class="code-keyword">return</span> request.getRelativeURL(); 
    }

    @Override
    <span class="code-keyword">public</span> <span class="code-object">boolean</span>
mergeVersion() {
        <span class="code-keyword">return</span> request.mergeVersion(); 
    }

    @Override
    <span class="code-keyword">public</span> <span class="code-object">String</span>
toString() {
        <span class="code-keyword">return</span> request.toString(); 
    }
}
</pre>
</div></div>

<h4><a name="WicketandlocalizedURLs-RequestCodingStrategyDecorator"></a>RequestCodingStrategyDecorator</h4>
<p>To do this, you'll need to create your own implementation of IRequestCodingStrategy.
</p>

<p>We need to have a decorator of IRequestCodingStrategy, below is the implementation:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>RequestCodingStrategyDecorator.java</b></div><div
class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">import</span> org.apache.wicket.IRequestTarget;
<span class="code-keyword">import</span> org.apache.wicket.Request;
<span class="code-keyword">import</span> org.apache.wicket.RequestCycle;
<span class="code-keyword">import</span> org.apache.wicket.request.IRequestCodingStrategy;
<span class="code-keyword">import</span> org.apache.wicket.request.RequestParameters;
<span class="code-keyword">import</span> org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy;

/**
 * Decorator of {@link IRequestCodingStrategy} <span class="code-keyword">interface</span>.
 *
 * @author Alex Objelean
 */
<span class="code-keyword">public</span> class RequestCodingStrategyDecorator
  <span class="code-keyword">implements</span> IRequestCodingStrategy {
  /**
   * Decorated strategy.
   */
  <span class="code-keyword">private</span> <span class="code-keyword">final</span>
IRequestCodingStrategy strategy;


  /**
   * Constructor.
   * @param strategy to decorate.
   */
  <span class="code-keyword">public</span> RequestCodingStrategyDecorator(<span
class="code-keyword">final</span> IRequestCodingStrategy strategy) {
    <span class="code-keyword">if</span> (strategy == <span class="code-keyword">null</span>)
{
      <span class="code-keyword">throw</span> <span class="code-keyword">new</span>
IllegalArgumentException(<span class="code-quote">"Strategy cannot be <span class="code-keyword">null</span>!"</span>);
    }
    <span class="code-keyword">this</span>.strategy = strategy;
  }

  /**
   * {@inheritDoc}
   */
  <span class="code-keyword">public</span> void addIgnoreMountPath(<span class="code-keyword">final</span>
<span class="code-object">String</span> path) {
    <span class="code-keyword">this</span>.strategy.addIgnoreMountPath(path);
  }


  /**
   * {@inheritDoc}
   */
  <span class="code-keyword">public</span> RequestParameters decode(<span class="code-keyword">final</span>
Request request) {
    <span class="code-keyword">return</span> <span class="code-keyword">this</span>.strategy.decode(request);
  }


  /**
   * {@inheritDoc}
   */
  <span class="code-keyword">public</span> CharSequence encode(<span class="code-keyword">final</span>
RequestCycle requestCycle, <span class="code-keyword">final</span> IRequestTarget
requestTarget) {
    <span class="code-keyword">return</span> <span class="code-keyword">this</span>.strategy.encode(requestCycle,
requestTarget);
  }


  /**
   * @<span class="code-keyword">return</span> decorated {@link IRequestCodingStrategy}.
   */
  <span class="code-keyword">public</span> <span class="code-keyword">final</span>
IRequestCodingStrategy getDecoratedStrategy() {
    <span class="code-keyword">return</span> <span class="code-keyword">this</span>.strategy;
  }


  /**
   * {@inheritDoc}
   */
  <span class="code-keyword">public</span> void mount(<span class="code-keyword">final</span>
IRequestTargetUrlCodingStrategy urlCodingStrategy) {
    <span class="code-keyword">this</span>.strategy.mount(urlCodingStrategy);
  }


  /**
   * {@inheritDoc}
   */
  <span class="code-keyword">public</span> CharSequence pathForTarget(<span
class="code-keyword">final</span> IRequestTarget requestTarget) {
    <span class="code-keyword">return</span> <span class="code-keyword">this</span>.strategy.pathForTarget(requestTarget);
  }


  /**
   * {@inheritDoc}
   */
  <span class="code-keyword">public</span> <span class="code-object">String</span>
rewriteStaticRelativeUrl(<span class="code-keyword">final</span> <span class="code-object">String</span>
string) {
    <span class="code-keyword">return</span> <span class="code-keyword">this</span>.strategy.rewriteStaticRelativeUrl(string);
  }


  /**
   * {@inheritDoc}
   */
  <span class="code-keyword">public</span> IRequestTarget targetForRequest(<span
class="code-keyword">final</span> RequestParameters requestParameters) {
    <span class="code-keyword">return</span> <span class="code-keyword">this</span>.strategy.targetForRequest(requestParameters);
  }


  /**
   * {@inheritDoc}
   */
  <span class="code-keyword">public</span> void unmount(<span class="code-keyword">final</span>
<span class="code-object">String</span> path) {
    <span class="code-keyword">this</span>.strategy.unmount(path);
  }

  /**
   * {@inheritDoc}
   */
  <span class="code-keyword">public</span> IRequestTargetUrlCodingStrategy urlCodingStrategyForPath(<span
class="code-keyword">final</span> <span class="code-object">String</span>
path) {
    <span class="code-keyword">return</span> <span class="code-keyword">this</span>.strategy.urlCodingStrategyForPath(path);
  }
}
</pre>
</div></div>

<h4><a name="WicketandlocalizedURLs-LocaleUrlCodingStrategyDecorator"></a>LocaleUrlCodingStrategyDecorator</h4>
<p>Next step is to create the coding strategy responsible for adding locale support
to your urls.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>LocaleUrlCodingStrategyDecorator.java</b></div><div
class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">import</span> java.util.HashSet;
<span class="code-keyword">import</span> java.util.Locale;
<span class="code-keyword">import</span> java.util.Set;

<span class="code-keyword">import</span> org.apache.commons.lang.LocaleUtils;
<span class="code-keyword">import</span> org.apache.commons.lang.StringUtils;
<span class="code-keyword">import</span> org.apache.log4j.Logger;
<span class="code-keyword">import</span> org.apache.wicket.IRequestTarget;
<span class="code-keyword">import</span> org.apache.wicket.RedirectToUrlException;
<span class="code-keyword">import</span> org.apache.wicket.Request;
<span class="code-keyword">import</span> org.apache.wicket.RequestCycle;
<span class="code-keyword">import</span> org.apache.wicket.Session;
<span class="code-keyword">import</span> org.apache.wicket.protocol.http.request.WebRequestCodingStrategy;
<span class="code-keyword">import</span> org.apache.wicket.request.IRequestCodingStrategy;
<span class="code-keyword">import</span> org.apache.wicket.request.RequestParameters;
<span class="code-keyword">import</span> org.apache.wicket.request.target.coding.AbstractRequestTargetUrlCodingStrategy;
<span class="code-keyword">import</span> org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy;
<span class="code-keyword">import</span> org.apache.wicket.request.target.component.IBookmarkablePageRequestTarget;
<span class="code-keyword">import</span> org.apache.wicket.request.target.component.IPageRequestTarget;


/**
 * Coding strategy that prepends locale to url, useful <span class="code-keyword">for</span>
caching localizable applications.
 * &lt;p&gt;
 * Changes the locale, depending on found locale in request path. Delegates the encoding/decoding
call to original
 * decorated coding strategy, but with processed request path (strip locale).
 *
 * @author Alex Objelean
 *
 */
<span class="code-keyword">public</span> class LocaleUrlCodingStrategyDecorator
  <span class="code-keyword">extends</span> RequestCodingStrategyDecorator {
	/**
	 * Simple implementation of {@link IRequestTargetUrlCodingStrategy}, used only to make wicket
filter treat original
	 * request as wicket related.
	 */
  <span class="code-keyword">private</span> <span class="code-keyword">static</span>
class PassThroughUrlCodingStrategy
		<span class="code-keyword">extends</span> AbstractRequestTargetUrlCodingStrategy
{
		/**
		 * Construct.
		 *
		 * @param path
		 */
		<span class="code-keyword">public</span> PassThroughUrlCodingStrategy(<span
class="code-keyword">final</span> <span class="code-object">String</span>
path) {
			<span class="code-keyword">super</span>(path);
		}

		/**
		 * {@inheritDoc}
		 */
		<span class="code-keyword">public</span> IRequestTarget decode(<span class="code-keyword">final</span>
RequestParameters requestParameters) {
			<span class="code-keyword">return</span> <span class="code-keyword">null</span>;
		}

		/**
		 * {@inheritDoc}
		 */
		<span class="code-keyword">public</span> CharSequence encode(<span class="code-keyword">final</span>
IRequestTarget requestTarget) {
			<span class="code-keyword">return</span> <span class="code-keyword">null</span>;
		}

		/**
		 * {@inheritDoc}
		 */
		<span class="code-keyword">public</span> <span class="code-object">boolean</span>
matches(<span class="code-keyword">final</span> IRequestTarget requestTarget)
{
			<span class="code-keyword">return</span> <span class="code-keyword">false</span>;
		}
	}
  /** log. */
  <span class="code-keyword">private</span> <span class="code-keyword">static</span>
org.apache.log4j.Logger log = Logger.getLogger(LocaleUrlCodingStrategyDecorator.class);

	/**
   * Set of supported locales.
   */
  <span class="code-keyword">private</span> <span class="code-keyword">final</span>
Set&lt;<span class="code-object">String</span>&gt; locales = <span
class="code-keyword">new</span> HashSet&lt;<span class="code-object">String</span>&gt;();


	/**
   * Construct.
   *
   * @param defaultStrategy The <span class="code-keyword">default</span> strategy
most requests are forwarded to
   */
  <span class="code-keyword">public</span> LocaleUrlCodingStrategyDecorator(<span
class="code-keyword">final</span> IRequestCodingStrategy defaultStrategy) {
    <span class="code-keyword">super</span>(defaultStrategy);
    locales.add(<span class="code-quote">"en"</span>);
    locales.add(<span class="code-quote">"ro"</span>);
    locales.add(<span class="code-quote">"pt"</span>);
    locales.add(<span class="code-quote">"es"</span>);
    locales.add(<span class="code-quote">"ru"</span>);
    locales.add(<span class="code-quote">"fr"</span>);
  }

  /**
	 * Decode the querystring of the URL. one.
	 *
	 * @see org.apache.wicket.request.IRequestCodingStrategy#decode(org.apache.wicket.Request)
	 */
	@Override
	<span class="code-keyword">public</span> RequestParameters decode(<span class="code-keyword">final</span>
Request request) {
<span class="code-comment">//		log.debug(<span class="code-quote">"&lt;decode&gt;"</span>);
</span><span class="code-comment">//		log.debug(<span class="code-quote">"\trequestUrl:
"</span> + request.getURL());
</span>		<span class="code-keyword">try</span> {
			<span class="code-keyword">final</span> <span class="code-object">String</span>
requestPathLocale = getRequestPathLocale(request);
			<span class="code-keyword">final</span> Locale locale = LocaleUtils.toLocale(requestPathLocale);
			<span class="code-keyword">if</span> (requestPathLocale != <span class="code-keyword">null</span>)
{
				<span class="code-keyword">if</span> (!Session.get().getLocale().equals(locale))
{
					log.debug(<span class="code-quote">"Changing locale to: "</span> + locale);
					Session.get().setLocale(locale);
				}
				<span class="code-keyword">final</span> <span class="code-object">String</span>
url = request.decodeURL(request.getURL());
				<span class="code-comment">// remove locale from request
</span>				<span class="code-keyword">final</span> <span class="code-object">String</span>
urlWithoutLocale = url.replace(getLocaleString(request.getLocale()), "");
<span class="code-comment">//				log.debug(<span class="code-quote">"DecodedUrl:
"</span> + urlWithoutLocale);
</span>				<span class="code-comment">// use decorator <span class="code-keyword">for</span>
decoding
</span>				<span class="code-keyword">return</span> getDecoratedStrategy().decode(<span
class="code-keyword">new</span> RequestDecorator(request) {
					@Override
					<span class="code-keyword">public</span> <span class="code-object">String</span>
getURL() {
						<span class="code-keyword">return</span> urlWithoutLocale;
					}

                                         @Override
                                         <span class="code-keyword">public</span>
<span class="code-object">String</span> getPath() {
                                                <span class="code-keyword">return</span>
urlWithoutLocale;    
                                         }
                                });
			} <span class="code-keyword">else</span> <span class="code-keyword">if</span>
(!request.getPath().startsWith(WebRequestCodingStrategy.RESOURCES_PATH_PREFIX)){
			  <span class="code-comment">//redirect to locale aware url <span class="code-keyword">for</span>
all request which are not resource related
</span>			  <span class="code-comment">//ISSUE: Redirect any url's without i18n
to the <span class="code-keyword">default</span> /en/ versions of those pages
</span>			  <span class="code-keyword">throw</span> <span class="code-keyword">new</span>
RedirectToUrlException(<span class="code-quote">"en/"</span> + request.getPath());
			}
			<span class="code-keyword">return</span> getDecoratedStrategy().decode(request);
		} <span class="code-keyword">finally</span> {
<span class="code-comment">//			log.debug(<span class="code-quote">"&lt;/decode&gt;"</span>);
</span>		}
	}


	/**
   * Encode the querystring of the URL
   */
  @Override
  <span class="code-keyword">public</span> CharSequence encode(<span class="code-keyword">final</span>
RequestCycle requestCycle, <span class="code-keyword">final</span> IRequestTarget
requestTarget) {
<span class="code-comment">//		log.debug(<span class="code-quote">"&lt;encode&gt;"</span>);
</span>		<span class="code-object">String</span> url = getDecoratedStrategy().encode(requestCycle,
requestTarget).toString();
		<span class="code-keyword">try</span> {
<span class="code-comment">//			log.debug(<span class="code-quote">"\turl: "</span>
+ url);
</span>			<span class="code-comment">//rewrite only requests <span class="code-keyword">for</span>
pages &amp; links (ignore others, like resources)
</span>			<span class="code-keyword">if</span> (requestTarget <span class="code-keyword">instanceof</span>
IBookmarkablePageRequestTarget || requestTarget <span class="code-keyword">instanceof</span>
IPageRequestTarget) {
				<span class="code-keyword">final</span> <span class="code-object">String</span>
localeString = getLocaleString(Session.get().getLocale());
				<span class="code-keyword">if</span> (url.startsWith(<span class="code-quote">"../"</span>))
{
					<span class="code-comment">//TODO move <span class="code-keyword">this</span>
logic to utility method?
</span>					<span class="code-comment">//last index is incremented by 3, because
../ has 3 characters
</span>					<span class="code-keyword">final</span> <span class="code-object">int</span>
lastIndex = url.lastIndexOf(<span class="code-quote">"../"</span>) + 3;
					<span class="code-keyword">final</span> <span class="code-object">String</span>
remainingUrl = url.substring(lastIndex);
					<span class="code-keyword">if</span> (StringUtils.isEmpty(remainingUrl))
{
		        <span class="code-keyword">return</span> url;
		      }
					url = url.substring(0, lastIndex) + localeString + remainingUrl;
					<span class="code-keyword">return</span> url;
				}
				<span class="code-comment">// <span class="code-keyword">if</span> starts
with . -&gt; skip
</span>				<span class="code-keyword">if</span> (url.startsWith(<span
class="code-quote">"."</span>)) {
					<span class="code-keyword">return</span> url;
				}
				url = localeString + url;
			}
			<span class="code-keyword">return</span> url;
		} <span class="code-keyword">finally</span> {
<span class="code-comment">//		  log.debug(<span class="code-quote">"\tEncoding:
"</span> + url);
</span><span class="code-comment">//		  log.debug(<span class="code-quote">"&lt;/encode&gt;"</span>);
</span>		}
	}

  /**
   * @param locale
   * @<span class="code-keyword">return</span>
   */
  <span class="code-keyword">private</span> <span class="code-object">String</span>
getLocaleString(<span class="code-keyword">final</span> Locale locale) {
    <span class="code-keyword">return</span> locale.getLanguage() + <span class="code-quote">"/"</span>;
  }

  /**
	 * Returns encoded locale in the request path. If none is found, <span class="code-keyword">null</span>
is returned.
	 *
	 * @param request
	 * @<span class="code-keyword">return</span>
	 */
	<span class="code-keyword">private</span> <span class="code-object">String</span>
getRequestPathLocale(<span class="code-keyword">final</span> Request request)
{
		<span class="code-keyword">final</span> <span class="code-object">String</span>
path = request.getPath();
		<span class="code-keyword">for</span> (<span class="code-keyword">final</span>
<span class="code-object">String</span> locale : locales) {
			<span class="code-keyword">if</span> (path.startsWith(locale + <span class="code-quote">"/"</span>))
{
				<span class="code-keyword">return</span> locale;
			}
		}
		<span class="code-keyword">return</span> <span class="code-keyword">null</span>;
	}


	/**
	 * Remove locale from path.
	 *
	 * @param path to strip.
	 * @<span class="code-keyword">return</span> path without locale.
	 */
	<span class="code-keyword">private</span> <span class="code-object">String</span>
stripLocaleFropPath(<span class="code-keyword">final</span> <span class="code-object">String</span>
path) {
		<span class="code-keyword">for</span> (<span class="code-keyword">final</span>
<span class="code-object">String</span> locale : locales) {
			<span class="code-keyword">final</span> <span class="code-object">String</span>
toStrip = locale + <span class="code-quote">"/"</span>;
			<span class="code-keyword">if</span> (path.startsWith(toStrip)) {
				<span class="code-keyword">return</span> path.replaceFirst(toStrip, "");
			}
		}
		<span class="code-keyword">return</span> path;
	}


	/**
   * {@inheritDoc}
   */
  @Override
  <span class="code-keyword">public</span> IRequestTarget targetForRequest(<span
class="code-keyword">final</span> RequestParameters requestParameters) {
  	<span class="code-comment">//delegate call to decorated codingStrategy, but with
locale removed
</span>  	<span class="code-keyword">final</span> <span class="code-object">String</span>
newPath = stripLocaleFropPath(requestParameters.getPath());
  	requestParameters.setPath(newPath);
  	<span class="code-keyword">return</span> <span class="code-keyword">super</span>.targetForRequest(requestParameters);
  }

  /**
   * {@inheritDoc}
   */
  @Override
  <span class="code-keyword">public</span> IRequestTargetUrlCodingStrategy urlCodingStrategyForPath(<span
class="code-keyword">final</span> <span class="code-object">String</span>
path) {
  	<span class="code-keyword">final</span> <span class="code-object">String</span>
newPath = stripLocaleFropPath(path);
  	<span class="code-keyword">if</span> (StringUtils.isEmpty(newPath)) {
			<span class="code-comment">// treat <span class="code-keyword">this</span>
kind of situation by returing some not <span class="code-keyword">null</span>
codingStrategy,
</span>  		<span class="code-comment">// to let <span class="code-keyword">this</span>
kind of request treated by wicket
</span>  		<span class="code-keyword">return</span> <span class="code-keyword">new</span>
PassThroughUrlCodingStrategy(newPath);
  	}
  	<span class="code-keyword">return</span> <span class="code-keyword">super</span>.urlCodingStrategyForPath(newPath);
  }

}
</pre>
</div></div>

<h4><a name="WicketandlocalizedURLs-Usage"></a>Usage</h4>
<p>In MyApplication.java, override newRequestCycleProcessor method &amp; add the
newly created LocaleUrlCodingStrategyDecorator.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>MyApplication.java</b></div><div
class="codeContent panelContent">
<pre class="code-java">
/** 
   * {@inheritDoc} 
   */ 
  @Override 
  <span class="code-keyword">protected</span> IRequestCycleProcessor newRequestCycleProcessor()
{ 
    <span class="code-keyword">return</span> <span class="code-keyword">new</span>
WebRequestCycleProcessor() { 
    @Override 
      <span class="code-keyword">protected</span> IRequestCodingStrategy newRequestCodingStrategy()
{ 
        <span class="code-keyword">return</span> <span class="code-keyword">new</span>
LocaleUrlCodingStrategyDecorator(<span class="code-keyword">super</span>.newRequestCodingStrategy());

      } 
    } 
  } 
</pre>
</div></div>

<h4><a name="WicketandlocalizedURLs-Conclusion"></a>Conclusion</h4>
<p>TODO.</p>
     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/WICKET/Wicket+and+localized+URLs">View
Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=4325577&revisedVersion=2&originalVersion=1">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/WICKET/Wicket+and+localized+URLs?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message