Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the role and lifecycle of StateHelper?

Tags:

jsf

jsf-2

I can see that EL attributes are stored in the StateHelper and String literals in the getAttributes() map of a component. What is the lifecycle and why the need for two containers?

Also at what points in the lifecycle are EL ValueExpression evaluated? (Every time the getStateHelper.eval() is called?)

like image 957
Ioannis Deligiannis Avatar asked May 11 '13 11:05

Ioannis Deligiannis


1 Answers

  1. StateHelper provides a convenience for component developers (who subclass UIComponent directly and not a standard component) to maintain the state of a component across requests. It plays an integral role in JSF view state saving and the underlying contract provides more than just a means to stash component attributes.

    By subclassing StateHelper, a component developer can more conveniently key into the saveState and restoreState methods of StateHolder, methods which are supposed to guarantee that a component (and child components) have their state correctly persisted (per the configured state saving mode) of the JSF Impl.

    Contrast that with getAttributes() map which is basically a stash of component variables, and is mostly relevant during the lifecycle of a single request. It offers no other services than to keep stuff.

  2. ValueExpression is evaluated at least 2x in a component's lifetime : RESTORE_VIEW and UPDATE_MODEL_VALUES phases, for obvious reasons: The first to give appropriate rendering of components and the second, to commit validated and converted values to the backing bean

like image 95
kolossus Avatar answered Sep 27 '22 22:09

kolossus