Propagating Client-Side View State

If your application stores view state on the client, you must propagate that state with your Ajax calls if you need access to view state.

To propagate view state, we implement a JavaScript function called getJSFState, which we call when the Zip Code changes.

image

The getJSFState function returns a string that we pass through to the request as a request parameter named javax.faces.ViewState. That string is the serialized version of the current component tree, which JSF previously stored in a hidden field named javax.faces.ViewState:

image

To get the serialized view state, we access the value of the hidden field with the special name javax.faces.ViewState. Then we escape all plus signs in the string and return it to the zipChanged function, which propagates the state.


image Note: Ajax and storing state on the client

When you store view state on the client, JSF serializes the view, optionally compresses it, and stores the resulting string in a hidden field. The name of the field, javax.faces.ViewState, is specified in the JSF 1.2 specification, so you can write code, such as the preceding JavaScript, that accesses the view state. However, earlier versions of the JSF specification did not explicitly define the name of that hidden field. As a result, if you’ve written code for JSF 1.1 that relies on that name, you may have to update your code for JSF 1.2.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.60.63