You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Dan <da...@gmail.com> on 2011/12/04 02:03:50 UTC
Wicket 1.5 LocaleFirstMapper and CustomHomeMapper bug when using
BookmarkablePageLink
LocaleFirstMapper structures my site to place the language code in the URL
path (e.g., example.com/en/path-to-page).
The LocaleFirstMapper and CustomHomeMapper classes work perfectly, but I
noticed that the language code was getting hacked off when I tried adding a
link to the home page:
add(new BookmarkablePageLink("homePageLink",
getApplication().getHomePage()));
The reason for this is in the method CustomHomeMapper.mapHandler(...):
public Url mapHandler(IRequestHandler requestHandler)
{
Url homeUrl = null;
if (requestHandler instanceof RenderPageRequestHandler)
{
RenderPageRequestHandler pageRequestHandler =
(RenderPageRequestHandler)requestHandler;
if
(pageRequestHandler.getPageClass().equals(Application.get().getHomePage()))
{
String locale = Session.get().getLocale().toString();
homeUrl = new Url();
homeUrl.getSegments().add(0, locale);
}
}
return homeUrl;
}
The requestHandler being passed in is an instance of
BookmarkablePageRequestHandler, and so the method returns null instead of
the URL to the "locale first" path.
This results in my link pointing to "example.com" instead of
"example.com/en"
The fix is simple - change the instanceof check to check for an instance of
the common interface IPageClassRequestHandler instead of only the
RenderPageRequestHandler class:
public Url mapHandler(IRequestHandler requestHandler)
{
Url homeUrl = null;
if (requestHandler instanceof IPageClassRequestHandler)
{
IPageClassRequestHandler pageRequestHandler =
(IPageClassRequestHandler)requestHandler;
if
(pageRequestHandler.getPageClass().equals(Application.get().getHomePage()))
{
String locale = Session.get().getLocale().toString();
homeUrl = new Url();
homeUrl.getSegments().add(0, locale);
}
}
return homeUrl;
}
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-5-LocaleFirstMapper-and-CustomHomeMapper-bug-when-using-BookmarkablePageLink-tp4155628p4155628.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Wicket 1.5 LocaleFirstMapper and CustomHomeMapper bug when using BookmarkablePageLink
Posted by Igor Vaynberg <ig...@gmail.com>.
fixed, thanks.
On Sat, Dec 3, 2011 at 5:03 PM, Dan <da...@gmail.com> wrote:
> LocaleFirstMapper structures my site to place the language code in the URL
> path (e.g., example.com/en/path-to-page).
>
> The LocaleFirstMapper and CustomHomeMapper classes work perfectly, but I
> noticed that the language code was getting hacked off when I tried adding a
> link to the home page:
>
> add(new BookmarkablePageLink("homePageLink",
> getApplication().getHomePage()));
>
>
> The reason for this is in the method CustomHomeMapper.mapHandler(...):
>
> public Url mapHandler(IRequestHandler requestHandler)
> {
> Url homeUrl = null;
>
> if (requestHandler instanceof RenderPageRequestHandler)
> {
> RenderPageRequestHandler pageRequestHandler =
> (RenderPageRequestHandler)requestHandler;
>
> if
> (pageRequestHandler.getPageClass().equals(Application.get().getHomePage()))
> {
> String locale = Session.get().getLocale().toString();
> homeUrl = new Url();
> homeUrl.getSegments().add(0, locale);
> }
> }
>
> return homeUrl;
> }
>
> The requestHandler being passed in is an instance of
> BookmarkablePageRequestHandler, and so the method returns null instead of
> the URL to the "locale first" path.
>
> This results in my link pointing to "example.com" instead of
> "example.com/en"
>
> The fix is simple - change the instanceof check to check for an instance of
> the common interface IPageClassRequestHandler instead of only the
> RenderPageRequestHandler class:
>
> public Url mapHandler(IRequestHandler requestHandler)
> {
> Url homeUrl = null;
>
> if (requestHandler instanceof IPageClassRequestHandler)
> {
> IPageClassRequestHandler pageRequestHandler =
> (IPageClassRequestHandler)requestHandler;
>
> if
> (pageRequestHandler.getPageClass().equals(Application.get().getHomePage()))
> {
> String locale = Session.get().getLocale().toString();
> homeUrl = new Url();
> homeUrl.getSegments().add(0, locale);
> }
> }
>
> return homeUrl;
> }
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-5-LocaleFirstMapper-and-CustomHomeMapper-bug-when-using-BookmarkablePageLink-tp4155628p4155628.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org