Skip to content

Instantly share code, notes, and snippets.

@armhold
Created March 27, 2012 21:37
Show Gist options
  • Save armhold/2220564 to your computer and use it in GitHub Desktop.
Save armhold/2220564 to your computer and use it in GitHub Desktop.
Wicket NoVersionHomePageMapper - don't show page version/id on home page
public class NoVersionHomePageMapper extends AbstractComponentMapper
{
/**
* If this is the home page URL, return a bigger compatibility score than
* {@link org.apache.wicket.request.mapper.HomePageMapper#getCompatibilityScore(Request)}
*
* @see org.apache.wicket.request.mapper.HomePageMapper#getCompatibilityScore(org.apache.wicket.request.Request)
*/
public int getCompatibilityScore(Request request)
{
return isHomeUrl(request) ? 1 : 0;
}
@Override
public Url mapHandler(IRequestHandler requestHandler)
{
if (requestHandler instanceof ListenerInterfaceRequestHandler)
{
return null;
}
if (requestHandler instanceof IPageRequestHandler)
{
IPageRequestHandler pageRequestHandler = (IPageRequestHandler)requestHandler;
if (pageRequestHandler.getPageClass().equals(Application.get().getHomePage()))
{
return new Url();
}
}
return null;
}
@Override
public IRequestHandler mapRequest(Request request)
{
return null;
}
/**
* A home URL is considered a URL without any segments
*
* @param request
* @return <code>true</code> if the request is to the home page ("/")
*/
private boolean isHomeUrl(Request request)
{
return request.getUrl().getSegments().isEmpty();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment