Thursday, June 23, 2011

JSF state saving mechanism ..

JSF can save state of component tree in either session or on clients machine inform of serialized data .
While creating component tree JSF creates a key and keep all objects of component tree as UIViewRoot in session with against it.For next JSF request it will use same key to restore that view :)
For client side saving has performance issues like it has to serialize whole tree and write it in response ship in form of gzip to client.Next time when same client make JSF request from same page it de-serialize it and inflate all objects in corresponding state .

Setting for state saving is done in web.xml.

Server side state saving is where the component tree and all component state are stored within the user's session. This entry within the session is tracked by writing a key in the response that is used to lookup the entry on subsequent post-backs.

Client side state saving doesn't leverage the server side session mechanism at all, instead, the component tree and state will be serialized using Java Serialization, GZIP compressed (at least that is the default), Base64 encoded, and written to the response. When a post-back occurs, the encoding process will be reversed which will result in the tree and state we started with.

As to the benefits/drawbacks, review the following table.


State Saving MethodServer Side Memory UsageCPU UsageBandwidth Usage
Server without compressionHighLowLow
Server with compressionLow/MediumHighLow
Client with compressionLowHighMedium
Client without compressionLowMedHigh



Setting in web.xml
  <context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>



1.Server side state saving - following hidden field is added (see the value )

<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="2269033803785808195:-5553424543391650776" autocomplete="off" />


observe >> value="2269033803785808195:-5553424543391650776"



2.Client side state saving - following hidden field is added (see the value )

<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="H4sIAAAAAAAAANVWTWwbRRQeOzFxflryU4UitZC6VSVKuo6TmEJCRZzEaVZxaIRDoCmQjr0Te9Px7mR21l63NCoHBEJCUHFCCuLAhQM9ceGCBOKAhFQQkbjABU6oBxBC4gCHipnxrncTskl6ZCU/z+6+efO975v3Zj/5DcSIRUHPGqxCxWY6VmahVZ6HJNb245df9V/5vgVEZ0AHNqE2A4vMpCpoZ2WKrLKJNYc8MwHE1VWLc9vNfzEGHlhb0TU2alPQdzkn42JolJSLhTVUZOPvfvvih93WYzgK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