JSF State in database
August 1, 2008 4 Comments
It’s a fact that JSF saves too much to be stateful. When statesaving is set to client, you can see the big javax.faces.ViewState hidden field with the encoded state. For users with low bandwith or mobile users this is an issue because of the size of the state written on the client. In case the state is kept on the server side, it solves the bandwith issues but allocates memory on httpsession.
I’ve written a custom experimental DBStateManager that keeps the state in the database. The token sent to the client is the identifier of the current state. The advantage is the gain of bandwitdh(a page’s size went from 140Kb to 26Kb) and no memory is allocated in httpsession, the drawback is the db hit (can be improved by caching). Btw it’s easy to plug-in your own implementation for state manager by;
<application> <state-manager>com.prime.faces.DBStateManager</state-manager> </application>
I’m one of the many that’s waiting for the state management enhancements in JSF 2.0. Saving only the delta changes
in the component state instead of the complete state of a component is a major improvement I’m looking forward to.