inferring locale from URL in 1.5

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

inferring locale from URL in 1.5

armhold
What's the cleanest way to set a user's locale based on the domainname of the URL of the request in 1.5?  

This guide relies on overriding newRequestCycleProcessor(). Would a proper 1.5 analog be to add a custom AbstractRequestCycleListener like this?

                RequestCycleListenerCollection listeners = new RequestCycleListenerCollection();
                application.getRequestCycleListeners().add(listeners);
                listeners.add(new AbstractRequestCycleListener() {
                        public void onBeginRequest(RequestCycle cycle) {
                               Session.get().setLocale(...);
                        }
   
               });

BTW, I've been asked to use the domainname for the locale (vs the context/servlet path), so my URLs will look like: fr.example.com/somepage.  

I'm planning to use (HttpServletRequest) getContainerRequest()).getServerName()) for this, unless there is something nicer.

Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: inferring locale from URL in 1.5

Martin Grigorov-4
Hi,

Check http://www.wicket-library.com/wicket-examples/mappers/ - LocaleFirstMapper

On Fri, Mar 23, 2012 at 2:04 AM, armhold <[hidden email]> wrote:

> What's the cleanest way to set a user's locale based on the domainname of the
> URL of the request in 1.5?
>
> https://cwiki.apache.org/WICKET/wicket-and-localized-urls.html This guide
> relies on overriding newRequestCycleProcessor(). Would a proper 1.5 analog
> be to add a custom AbstractRequestCycleListener like this?
>
>                RequestCycleListenerCollection listeners = new
> RequestCycleListenerCollection();
>                application.getRequestCycleListeners().add(listeners);
>                listeners.add(new AbstractRequestCycleListener() {
>                        public void onBeginRequest(RequestCycle cycle) {
>                               Session.get().setLocale(...);
>                        }
>
>               });
>
> BTW, I've been asked to use the domainname for the locale (vs the
> context/servlet path), so my URLs will look like: fr.example.com/somepage.
>
> I'm planning to use (HttpServletRequest)
> getContainerRequest()).getServerName()) for this, unless there is something
> nicer.
>
> Thank you.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/inferring-locale-from-URL-in-1-5-tp4497412p4497412.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>



--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: inferring locale from URL in 1.5

armhold
Martin,

The wicket-examples site rarely works for me (server under-resourced?) but I found the code in the examples section of the Wicket source from git.

LocaleFirstMapper was a huge help; I'm fairly sure I wouldn't have gotten it working without that reference, so thank you very much.  Here's what I came up with:

https://gist.github.com/2198074

I suspect that stripping the locale from the hostname (vs path segment) is not needed, since you were probably doing that in your example so that the locale doesn't show up as a parameter to the page. I'm still experimenting with it.

Thanks again for your help.
Reply | Threaded
Open this post in threaded view
|

Re: inferring locale from URL in 1.5

Martin Grigorov-4
wicketstuff.org is the one that is down most of the time.
wicket-library.com is OK, I've never had problems with it.

On Sun, Mar 25, 2012 at 7:39 PM, armhold <[hidden email]> wrote:

> Martin,
>
> The wicket-examples site rarely works for me (server under-resourced?) but I
> found the code in the examples section of the Wicket source from git.
>
> LocaleFirstMapper was a huge help; I'm fairly sure I wouldn't have gotten it
> working without that reference, so thank you very much.  Here's what I came
> up with:
>
> https://gist.github.com/2198074

This shows that the new IRequestMapper/IRequestHandler impls are very
flexible :-)

>
> I suspect that stripping the locale from the hostname (vs path segment) is
> not needed, since you were probably doing that in your example so that the
> locale doesn't show up as a parameter to the page. I'm still experimenting
> with it.
>
> Thanks again for your help.

Have fun! :-)

>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/inferring-locale-from-URL-in-1-5-tp4497412p4503485.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>



--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: inferring locale from URL in 1.5

armhold
Try clicking the "source code" links from wicket-library.com. Always times out for me.
Reply | Threaded
Open this post in threaded view
|

Re: inferring locale from URL in 1.5

Martijn Dashorst
Administrator
You could try http://wicket-examples.herokuapp.com but that is not an
officially supported deployment.

Martijn

On Mon, Mar 26, 2012 at 3:17 PM, armhold <[hidden email]> wrote:

> Try clicking the "source code" links from wicket-library.com. Always times
> out for me.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/inferring-locale-from-URL-in-1-5-tp4497412p4505742.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>



--
Become a Wicket expert, learn from the best: http://wicketinaction.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: inferring locale from URL in 1.5

Martin Grigorov-4
In reply to this post by armhold
Nice!
It is just RequestMappers application. Somehow it extracts the
internal port of Tomcat instead of using the external (Apache HTTPD)
port.
Viewing sources of any other demo app works OK.

On Mon, Mar 26, 2012 at 3:17 PM, armhold <[hidden email]> wrote:

> Try clicking the "source code" links from wicket-library.com. Always times
> out for me.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/inferring-locale-from-URL-in-1-5-tp4497412p4505742.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>



--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: inferring locale from URL in 1.5

armhold
Hmm, I was actually planning to use that code (LazyHttpsConfig)
myself. Looked like a nice way to avoid hard-coding port numbers for
dev vs prod use.  Maybe not now. :-)