previous | index | next

Propagating Client Side View State

Our application doesn't store view state on the client side.

If it did, then the view state would have to be propagated back to the server in your Ajax calls.

Every JSF page (since version 1.2) stores a serialized version of the current component tree in a hidden field whose name is javax.faces.ViewState.

You can access it in JavaScript with:

   var jsfState = 
     window.document.getElementsByName("javax.faces.ViewState");

When making an Ajax call, the view state is sent back as a request parameter:

   new Ajax.Request(
      window.document.forms[0].action,
          {method: "post",
           parameters: "ajax=true&zip=" + zip + "&javax.faces.ViewState=" + jsfState,
           onComplete: processRealtimeValidation
          });

There are additional issues concerning extracting components from the view and preparing the string for propagation.


previous | index | next