The Java EE 5 Tutorial

Specifying Where State Is Saved

When implementing the state-holder methods (described in Saving and Restoring State), you specify in your deployment descriptor where you want the state to be saved, either client or server. You do this by setting a context parameter in your deployment descriptor.

    To specify where state is saved using NetBeans IDE, do the following:

  1. Expand the node of your project in the Projects pane.

  2. Expand the Web Pages and WEB-INF nodes that are under the project node.

  3. Double-click web.xml.

  4. After the web.xml file appears in the editor pane, click General at the top of the editor pane.

  5. Expand the Context Parameters node.

  6. Click Add.

  7. In the Add Context Parameter dialog:

    1. Enter javax.faces.STATE_SAVING_METHOD in the Param Name field.

    2. Enter client or server in the Param Value field.

    3. Click OK.

    To specify where state is saved by editing the deployment descriptor directly follow these steps:

  1. Add a context-param element to the deployment descriptor.

  2. Add a param-name element inside the context-param element and give it the name javax.faces.STATE_SAVING_METHOD.

  3. Add a param-value element to the context-param element and give it the value client or server, depending on whether you want state saved in the client or the server.

If state is saved on the client, the state of the entire view is rendered to a hidden field on the page. The JavaServer Faces implementation saves the state on the client by default. Duke’s Bookstore saves its state in the client.