This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Jsp Integration
Skip to end of metadata
Go to start of metadata

Integration in general

If you want to migrate an existing JSP based application to Wicket, then there are some quirks you need to take care of.

This page outlines the steps to enable putting Wicket generated content inside an existing web page.

Note: If the aim is to create a new page, and decorate it with existing header, footer or sidebars, then a better alternative is probably Sitemesh

  • use jsp:include to include the url to your wicket page
  • you (probably) can't use redirections, since wicket will redirect to it's own page. If so, override beforeCallComponent in your page:

    public void beforeCallComponent(Component component, RequestListenerInterface listener) { setRedirect(false); }
  • Because you're using include/forward, the default ServletWebRequest.getPath method will return null. Therefore, you need a specially created one:

in your Application class, override newWebRequest:

protected WebRequest newWebRequest(final HttpServletRequest servletRequest) { if (servletRequest.getPathInfo() == null) { if (servletRequest.getAttribute("javax.servlet.include.request_uri") != null) { return new IncludedServletWebRequest(servletRequest); } if (servletRequest.getAttribute("javax.servlet.forward.request_uri") != null) { return new ForwardedServletWebRequest(servletRequest); } log.error("Could not find an implementation of WebRequest that fits this request. trying the default"); } return super.newWebRequest(servletRequest); }

here are the needed implementations:

public class BaseServletWebRequest extends ServletWebRequest { {panel} public BaseServletWebRequest(HttpServletRequest httpServletRequest) { super(httpServletRequest); } {panel} {panel} public String getRelativeURL() { /** * Servlet 2.3 specification : * * Servlet Path: The path section that directly corresponds to the * mapping which activated this request. This path starts with a "/" * character except in the case where the request is matched with the * "/*" pattern, in which case it is the empty string. * * PathInfo: The part of the request path that is not part of the * Context Path or the Servlet Path. It is either null if there is no * extra path, or is a string with a leading "/". */ String url = getServletPath(); final String pathInfo = getPath(); {panel} {panel} if (pathInfo != null) { url += pathInfo; } {panel} {panel} final String queryString = getHttpServletRequest().getQueryString(); {panel} {panel} if (queryString != null) { url += ("?" + queryString); } {panel} {panel} // If url is non-empty it has to start with '/', which we should lose if (!url.equals("")) { // Remove leading '/' url = url.substring(1); } return url; } {panel} } public class ForwardedServletWebRequest extends BaseServletWebRequest { {panel} public ForwardedServletWebRequest(HttpServletRequest httpServletRequest) { super(httpServletRequest); } {panel} {panel} public String getPath() { return (String)getHttpServletRequest().getAttribute("javax.servlet.forward.path_info"); {panel} {panel} } {panel} {panel} public String getContextPath() { return (String)getHttpServletRequest().getAttribute("javax.servlet.forward.context_path"); } {panel} {panel} public String getServletPath() { return (String)getHttpServletRequest().getAttribute("javax.servlet.forward.servlet_path"); } {panel} } public class IncludedServletWebRequest extends BaseServletWebRequest { {panel} public IncludedServletWebRequest(HttpServletRequest httpServletRequest) { super(httpServletRequest); } {panel} {panel} public String getPath() { return (String)getHttpServletRequest().getAttribute("javax.servlet.include.path_info"); {panel} {panel} } {panel} {panel} public String getContextPath() { return (String)getHttpServletRequest().getAttribute("javax.servlet.include.context_path"); } {panel} {panel} public String getServletPath() { return (String)getHttpServletRequest().getAttribute("javax.servlet.include.servlet_path"); } {panel} }

Partial migration with wicketstuff-jee-web

If you want to migrate your application partial and stepwise you can use wicketstuff-jee-web. The advantage is that you are able to let your JSP / Servlets interact with Wicket pages.

A user guide can be found here:

An article and examples here:

  • No labels