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 simplified. See source code and javadocs to find out how Wicket really works.

To make it clear "request processing" here means all actions which take place within HttpServlet#doGet/doPost() or Filter#doFilter() method call. These is no single class in Wicket that does all the job. Classes delegate request processing to each other and in . In a very simplified way in may look it goes like this:
Image Removed
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.
Image Added

1.browser requests a URL
2.WicketFilter/Servlet receives request from servlet container and creates RequestCycle object (it's created for every request)
3.RequestCycle processes request in several steps, using for this IRequestCycleProcessor
4.Depending on request parameters IRequestCycleProcessor creates IRequestTarget (in Wicket this process is referred to as "resolving")
5.IRequestTarget use existing Page or creates new one, optionally run callbacks (user code which handles link clicks, form submits, etc.), asks Page and Components to render
6.Page/Components render themselves what means to produce markup and write it to HttpResponse
7.servlet container writes output to browser

TDB: use it somewhere else? – In general the aim of request processing is to:
(optionally) execute code which somehow changes data (stored in http session, database or elsewhere)
output HTML page to HttpServletResponse (output may reflect data change)

There are more classes involved in request processing. Below is short description of each of these classes. Descriptions say what is the purpose of the classThere 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 say what this class for, when it is created, how you can to get it its instance(s). You can skip the descriptions and look at the sequence diagram at the bottomIt's also a good idea to look at these classes' javadocs.

Panel
bgColor#FFFFFF
titleRelation between classes involved in request processing
borderStyledashed

Anchor
WebApplication
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

RequestCycle delegates most of request processing to IRequestCycleProcessor (see RequestCycle#step()). Besides that RequestCycle 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:

...

Code Block
java
java
final WebRequestCycle webRequestCycle = (WebRequestCycle) RequestCycle.get();
        webRequestCycle.getWebRequest().getHttpServletRequest();
        webRequestCycle.getWebResponse().getHttpServletResponse();

Anchor
WebSessionWebSession
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 WebSession is stored in HttpSession and restored from there on next request. If HttpSession expires and WebSession in which is stored 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.
Anchor
IRequestCycleProcessor
IRequestCycleProcessor

IRequestCycleProcessor

IRequestCycleProcessor is responsible for handling the steps of a request cycle. Its methods are called in a pre-defined order:

...

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 get its instance by WebApplication#getRequestCycleProcessor().

Anchor
WebSession
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 WebSession is stored in HttpSession and restored from there on next request. If HttpSession expires and WebSession in which is stored 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.

Anchor
IRequestCodingStrategy
IRequestCodingStrategy

IRequestCodingStrategy

IRequestCodingStrategy 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:

...

There is one instance of IRequestCodingStrategy per IRequestCycleProcessor. It is usually WebRequestCodingStrategy which is lazily created during the first request. Its creation can be customized by overriding AbstractRequestCycleProcessor#newRequestCodingStrategy().
See also Request coding strategy page.

Anchor
IRequestTarget
IRequestTarget

IRequestTarget

IRequestTarget 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 created, if a link is pressed ListenerInterfaceRequestTarget will be created.
You can get current request target by calling RequestCycle#getRequestTarget().
See also Request targets page.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 event processing and rendering. Note that event processing happens before rendering. That is why if a page is changed in event handling code, those changes are visible in the rendering phase.
Anchordiagramdiagram

...