Operating Stateless

Tapestry applications can operate in a stateless mode, that is, without a HttpSession. The framework automatically creates a session when needed; when the Visit object is first created, or when any persistent page properties are changed.

Ideally, the Home page of the application should not trigger the creation of a session: it should be careful not to create the Visit object. Remember that hits on your application will form a curve: The Home page is at the top of the curve, and it drops of rapidly as users penetrate deeper into the application ... how many times have you visited the front page of a web site and gone no further?

Stateless operations will affect ActionLink, DirectLink and Form components on your pages. By default, they will reject requests while the application is running stateless; the user will be redirected to the StaleSession page. This is appropriate, since normally, the lack of a session means that the previous session timed out and was discarded.

Each of these components has a stateful parameter which may be bound to false. When stateful is false, the components will accept stateless requests.

As the developer, you must keep a careful eye on what's stateful vs. stateless, and look to move stateless data into the engine, so as to avoid creating a visit object as long as possible. For example, the engine can resolve and store EJB home interfaces and references to stateless session EJBs. Even read-only database data can be stored in the engine. However, anything that is related to a particular user must be stored in the visit object (or a persistent page property).

It is also important to not accidentally create the visit object. Every page includes a visit property which will create the visit if it doesn't already exist. This will, in turn, force the creation of an HttpSession. On the other hand, the property path engine.visit will not create the visit object. To avoid creating the visit, you may need to wrap some of your HTML template inside a Conditional component whose condition parameter is bound to the property engine.visit.