Partial state saving does not mean that the state won't be saved in the session. It only means that a part of the component tree state will be saved instead of the entire component tree state. The key idea of partial state saving is that the state of components which wouldn't be changed by the client side in the subsequent request won't be saved. Instead, it is obtained by re-executing the view on the server side during restore view. Only the component state which is sensitive to changes by the client (forms, inputs, buttons, etc) will be saved. The 1K which you see in session is the partial state itself.
To test it yourself, toggle the state on and off by the following context-param
in web.xml
:
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
You'll see that the size increases when the setting is false
, which means that the entire component tree is been saved instead.
It is stored in session because that's the only provided by the Servlet API which has a larger scope than the request scope. Storing in request scope would have no value since it wouldn't be available anymore on the subsequent request. The Servlet API has no notion of the view scope like as JSF has (which is under the covers indirectly using the session scope by the way, basically, the view state is the component tree state).
You indeed don't see it anymore when you remove the form since there's actually nothing left which the client could change (i.e. there would be no postback). It would not make sense to save the state then. Besides, there would be nothing to pass the key of the saved state as a hidden input field (with the name javax.faces.ViewState
).
See also: