JSF Tip #22 - The JSF PartialStateHolder API

The definition of a PartialStateHolder according to the PartialStateHolder interface:

  void clearInitialState() 
  boolean initialStateMarked() 
  void markInitialState()

Note that the methods above do not mention that a PartialStateHolder extends from StateHolder. Be aware that if you want to implement partial state saving you will also need to implement the methods of the StateHolder interface. Having that said, what are the 3 methods used for?

The clearInitialState method

The clearInitialState method can be used to tell the JSF runtime that you are no longer interested in partial state saving and that you want full state saving.

The initialStateMarked method

The initialStateMarked method can be used to determine if the PartialStateHolder has its initial state marked.

The markInitialState method

The markInitialState method will be called by the JSF runtime after creating components and adding them to the component tree. Once this method is called the component will track changes since the initial state.

OK that is all interesting but how does that work for real? Well imagine the following:

Component construction during Render Response

  1. Create the component
  2. Add the component to the component tree
  3. Call markInitialState on the component

Component construction during Restore View

  1. Create the component
  2. Restore the component state from partial state

Posted October 18, 2012