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: [email protected]
For additional commands, e-mail: [email protected]