views:

492

answers:

2

So I was reading another question under the Wicket tag comparing Apache Wicket and Apache Click. A concise explanation, in my opinion. I am more familiar with the Wicket world than the Click world.

One of the comments I read was that you can make stateless Wicket pages. I started to think about this and couldn't figure out a way to make a request or a page request for something stateless. This could certainly come in handy in some situations. So how does one start to use Wicket without state?

+3  A: 

If a page is bookmarkable and doesn't contain any non-stateless components/behaviors then the page is automatically stateless and not stored in the session. I think that as long as a user visits only stateless pages, a session will not be created. For the most part, if everything about how the page is displayed can be determined solely from a no-args constructor or a constructor taking a PageParameters argument. The normal Link and Form classes are not stateless, so you'll need to use StatelessForm and StatelessLink instead.

Geoff Reedy
Thanks Geoff. Now the existence of those Stateless... components make sense as well.
Matt
+2  A: 

By default wicket is stateless, and wicket switches into stateful mode when it needs to. It is very easy to break the stateless mode. What I found useful is to annotate your intended stateless pages and stateless components with the @StatelessComponent annotation found in wicket-devutils project and then adding a StatelessChecker in my WebApplication init method like this:

protected void init(){ ... this.addPostComponentOnBeforeRenderListener(new StatelessChecker()); ... } This way I always get an exception about the offending stateful component.