Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

A Wicket application runs in any J2EE compliant application server by
defining a Java servlet filter in the application's web.xml file:

Code Block
xml
xml
	<?xml version="1.0" encoding="UTFISO-8859-81"?>
	<!DOCTYPE web<web-app
		  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
		  " xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/dtdns/javaee/web-app_2_3.dtd5.xsd"
	version="2.5">

	<web-app>

		<display-name>My Wicket Application</display-name>

		<servlet>
			<servlet-name>HelloWorldApplication</servlet-name>
			<servlet-class>wicket.protocol.http.WicketServlet</servlet-class>
	<display-name>wicketproject</display-name>

	<!--
		There are three means to configure Wickets configuration mode and they 
		are tested in the order given.
		
		1) A system property: -Dwicket.configuration 
		2) servlet specific <init-param> 
		3) context specific <context-param>

		The value might be either "development" (reloading when templates change) or 
		"deployment". If no configuration is found, "development" is the default. -->

	<filter>
		<filter-name>wicket.wicketproject</filter-name>
		<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
		<init-param>
			  <param-name>applicationClassName</param-name>
			  <param-value>wicketvalue>com.examplesyourcompany.helloworld.HelloWorldApplication<WicketApplication</param-value>
			</init-param>
			<load-on-startup>1</load-on-startup>
		</servlet>filter>

		<servlet<filter-mapping>
			<servlet-name>HelloWorldApplication</servlet<filter-name>wicket.wicketproject</filter-name>
			<url-pattern>/helloworld/*</url-pattern>
		</servlet-mapping>

		<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		</welcome-file-list>

	filter-mapping>
</web-app>

The servlet-filter class specified will always be "org.apache.wicket.protocol.http.WicketServletWicketFilter". The "applicationClassName" init-param provided must be the name of a WebApplication subclass. In the case above, it is "wicketcom.examplesyourcompany.helloworld.HelloWorldApplicationWicketApplication".

When WicketServlet WicketFilter is loaded, it will use this information to instantiate a single instance of your application class.

Servicing a Request

The following three steps occur each time that WicketServlet handles WicketFilter intercepts a request and a redirect is not required:

  1. it sets the application to the thread context
  2. the application creates a WebRequest, WebResponse and RequestCycle
  3. the RequestCycle's processRequestAndDetach
  4. Wicket asks the Application class to create a Session for the servlet request. If no session exists for the incoming request, a Session object is created using the application's session factory.
  5. The Session returned by the Application is asked to create a RequestCycle object using the Session's request cycle factory.
  6. The RequestCycle's request() method is called to handle the request.

How RequestCycle Handles a Request

...

  1. Calls the overridable method onBeginRequest() to allow RequestCycle subclasses to do things at the beginning of each request, such as opening a Hibernate session.
  2. Parses the request and potentially invokes user request handling code. If request handling sets the responsePage property of the RequestCycle, the request() method is called on the response page.
  3. Resolves the IRequestHandler to handle the request.
  4. Calls any listeners to onRequestHandlerResolved
  5. Calls requestHandlerExecutor.execute(handler); which in turn calls IRequestHandler.respond(). See API for a list of implementations.
  6. Calls any listeners to onRequestHandlerExecuted
  7. Calls Calls the overridable method onEndRequest() to allow RequestCycle subclasses to do things at the end of each request, such as closing a Hibernate session.

Step 2 3 may involve some pretty sophisticated logic. When a request URL is parsed, it may include information such as a Component listener
to invoke. This Component listener may create a whole new Page that is used

How Page Handles a Request

Page.request(), called in step 2 above, performs the following 3
steps to handle a request:

  1. Calls onBeginRequest() for every Component on the Page, giving each Component a chance to alter itself before rendering begins.
  2. Renders the Page by calling Page.render().
  3. If the Application for the Page has component checking enabled in its ApplicationSettings, checks that each component rendered.
  4. Calls onEndRequest() for every Component on the Page.

Once step 2 begins (the render phase for the Page), the Page becomes immutable and it is no longer valid to alter either the Page's component hierarchy or the values of any of its models. Attempting to change the Page during rendering will generally result in a runtime exception.

Clustering

When a Page is replicated from one machine in a cluster to another, the onSessionAttach() method will be called for every component on the Page.

...