You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

How it was in Wicket 1.4

To mount a page in Wicket 1.4 the developer had to use org.apache.wicket.protocol.http.WebApplication's:

  • #mount(IRequestTargetUrlCodingStrategy)
  • #mount(String, PackageName)
  • #mountBookmarkablePage(String, Class<T>)
  • #mountBookmarkablePage(String, String, Class<T>)
    an to mount a resource:
  • #mountSharedResource(String, String)
    For more information about these methods check https://cwiki.apache.org/WICKET/url-coding-strategies.html

The new way in Wicket 1.5

org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy interface and all its implementations are replaced with the org.apache.wicket.request.IRequestMapper and its respective implementations.
To add a mapper into the list of mappers which Wicket will use to process a request use org.apache.wicket.Application.getRootRequestMapperAsCompound().add(mapperInstance). When a request comes Wicket will ask all registered mappers whether they are able to process the request. Mappers with bigger org.apache.wicket.request.IRequestMapper.getCompatibilityScore(Request) are asked first. So Wicket calls org.apache.wicket.request.IRequestMapper.mapRequest(Request) for each mapper and if it returns non-null IRequestHandler then this is the handler which will be used to process the current request. In #mapRequest(Request) the mapper have to check request's segments (this is similar to httpServletRequest#getPath()) and request's parameters (get and post) and decide whether they match to the mapper's functionality. For example HomePageMapper is the mapper used to process the requests for all requests without any segments, i.e. requests to '/' with or without any query parameters.
The actual processing of the request is being done with org.apache.wicket.request.IRequestHandler.respond(IRequestCycle). During the processing Wicket will ask the mappers to create a org.apache.wicket.request.Url objects for each callback handler (e.g. link, form, ....) via org.apache.wicket.request.IRequestMapper.mapHandler(IRequestHandler)

Default mapper implementations

HomePageMapper

This mapper is pre-configured by Wicket and there is no need to register it. It is used to create IRequestHandler for requests to the root ('/') of the application context.

BookmarkableMapper

This mapper decodes and encodes bookmarkable URLs like:

  • /wicket/bookmarkable/com.example.pages.MyPage - using BookmarkablePageRequestHandler for stateless pages and using RenderPageRequestHandler for stateful/hybrid pages
  • /wicket/bookmarkable/com.example.pages.MyPage?2-click-foo-bar-baz - using BookmarkableListenerInterfaceRequestHandler to process bookmarkable listeners (e.g. Behavior).

This mapper is also pre-configured and there is no need to register it.

MountedMapper

This mapper is similar to BookmarkableMapper but the difference is that the user application defines the mount point where this mapper matches.
For example:

  • /path/to/page1
  • /path/to/pageN
  • /path/to/page?2-5.click.1-foo-bar-baz (2 is the page version, 5 is render count, 1 is behavior index)

Usage:

MyApp.java:

public void init() {
	super.init();

	getRootRequestMapperAsCompound().add(new MountedMapper("/mount/point", MyPage.class));
	mountPage("/mount/point", MyPage.class); // convenient method doing the same as above
}

PackageMapper

This mapper can mount a whole package. That is you mount a single page with a mount path prefix and then the mapper knows how to map all Page implementations in that package.

Usage:

MyApp.java:

public void init() {
	super.init();

        getRootRequestMapperAsCompound().add(
			new MountMapper("/mount/point", new PackageMapper(
				PackageName.forClass(Page3.class))));
        mountPackage("/mount/point", Page3.class);
}

Assuming that PageA package is "com.example.pages" a request to "/mount/point/PageB" will use com.example.pages.PageB if it exists and is an instance of Page.

ResourceMapper

A mapper which mounts ResourceReference implementations.

Usage:

MyApp.java:

public void init() {
	super.init();

	getRootRequestMapperAsCompound().add(new ResourceMapper("/company/logo", new PackageResourceReference(MyPage.class, "res/logo.gif")));
	mountResource("/company/logo", new PackageResourceReference(MyPage.class, "res/logo.gif"))); // convenient method doing the same as above
}

CryptoMapper

A wrapper around another mapper which will encrypt/decrypt the URLs generated by the inner one.

Usage:
MyApp.java:

public void init() {
	super.init();

        IRequestMapper cryptoMapper = new CryptoMapper(getRootRequestMapper(), this));
	setRootRequestMapper(cryptoMapper);
}

HttpsMapper

A mapper which makes a redirect to the same URL with HTTPS protocol if the requested page is annotated with @RequireHttps or to HTTP protocol if the last processed page had @RequireHttps and the one going to be processed has no such annotation.

Usage:

 public class MyApplication extends WebApplication
 {
  	public void init()
  	{
  		super.init();
  
  		getRootRequestMapperAsCompound().add(new MountedMapper("secured", HttpsPage.class));
  
  		setRootRequestMapper(new HttpsMapper(getRootRequestMapper(), new HttpsConfig(80, 443)));
  	}
 }
  • No labels