Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Note
titleThis is not exactly how Wicket 1.3 works

Some of the things are grossly simplified. See source code and javadocs to find out how Wicket really works.

There are a number of classes involved in request processing. The most important ones are: #WebApplication, #WebRequest, #WebResponse, #WebSession, #RequestCycle, #IRequestCycleProcessor, #IRequestCodingStrategy and #IRequestTarget. These is no single class that does all the job. Classes delegate request processing to each other and in a very simplified way in may look like this:

Here request processing starts with WicketFilter/Servlet being called by servlet container and "ends" with IRequestTarget which asks page to render and/or calls event handling code.

There is a number of classes involved in request processing. The most important ones are: #WebApplication, #WebRequest, #WebResponse, #WebSession, #RequestCycle, #IRequestCycleProcessor, #IRequestCodingStrategy and #IRequestTarget. Below there are short descriptions of these classes which says what this class for, when it is created, how you can get its instance(s). You can skip the descriptions and look at the sequence diagram at the bottom.

Anchor
WebApplication
WebApplication

WebApplication contains some classes (such as IRequestCycleProcessor) which are essential for request processing. It is also used for storing application scope data such as Settings and SharedResources.
WebApplication is created when WicketFilter/Servlet is initialized. It is created by IWebApplicationFactory which can be specified in the web.xml using applicationFactoryClassName parameter:

...

Anchor
RequestCycle
RequestCycle

RequestCycle does some general request processing and delegates most of it to IRequestCycleProcessor (see RequestCycle#step()). RequestCycle also contains instances of WebRequest, WebResponse which basically wraps HttpServletRequest and HttpServletResponse adding Wicket related functionality. Instances of all these classes are created on every request.
This is a pseudo code of how RequestCycle is created:

...

Anchor
WebSession
WebSession

WebSession holds information about a user session including some fixed number of most recent pages. WebSession roughly corresponds to HttpSession. It is lazily created during request handling. Then it WebSession is stored in HttpSession and restored from there on next request. If HttpSession expires and WebSession in which is stored in it can't be reached anymore new WebSession instance is created.
To customize Session creation you can override Application#newSession().
You can get instance of Session using Session#get() method.

...

  • IRequestTarget resolve(RequestCycle, RequestParameters) is called to get the request target. A request might refer to e.g. a bookmarkable page, a component on a previously rendered page. This is one of the main responsibilities of IRequestCycleProcessor. RequestParameters here consists of possible optional parameters that can be translated from servlet request parameters and serves as a strongly typed variant of these (see IRequestCodingStrategy).
  • void processEvents(RequestCycle) is called after the target is resolved. It is meant to handle events like calls on components e.g. onClick(), onSubmit() event handlers.
  • void respond(RequestCycle) is called to create a response to the requesting client i.e. generate web page or do redirect.
    Typically IRequestCycleProcessor resolves creates target and then delegates event processing and response generation to this target.

There is one instance of IRequestCycleProcessor per Application. It is lazily created during the first request. Its creation can be customized by overriding WebApplication#newRequestCycleProcessor(). You can its instance by WebApplication#getRequestCycleProcessor().

Anchor
IRequestCodingStrategy
IRequestCodingStrategy

IRequestCodingStrategy implementations are implementation is responsible for digesting the incoming request and creating a suitable RequestParameters object for it, as well as creating URL representations for request targets. These are methods that do it:

...

Anchor
IRequestTarget
IRequestTarget
There are different subclasses of
IRequestTarget for different types of requests. For instance is responsible for calling event handling code (for example onSubmit() method) and asking pages and components to render. IRequestTarget is created by IRequestCycleProcessor on every request. Which subclass of IRequestTarget will be created depends on RequestParameters instance which is decoded from requested URL. For example if a bookmarkable page is requested BookmarkablePageRequestTarget will be usedcreated, if a link is pressed on a rendered page ListenerInterfaceRequestTarget will be used. These targets will actually ask the page to render or call event handling code (for instance onSubmit() method).
Instance of IRequestTarget is created on every request by the request cycle processor.
You can get current request target by calling RequestCycle#getRequestTarget().

On the whole request processing looks roughly like this:. Here RequestCycle gets the request() message from WicketFilter/Servlet. The main idea behind the diagram is that requested URL is transformed into RequestParameters and then using it IRequestCycleProcessor creates IRequestTarget object and delegates to it events processing and rendering.