jsfviewroot

When ViewRoot is created in JSF?


In JSF a view root is created for every JSF page. When it is constructed?

Does it construct every time when view renders or depends on backing bean initialization?


Solution

  • In JSF a view root is created for every JSF page. When it is constructed?

    Basically, when JSF lifecycle calls ViewHandler#createView(), which will in turn call the ViewDeclarationLanguage#createView(). That can happen during restore view phase. But that can also happen during render response phase when a navigation has taken place. Or when JSF needs to extract metadata from a given view. It can also happen anytime when custom code explicitly calls ViewHandler#createView(). Nothing in the JSF specification restricts that to a specific moment.


    Does it construct every time when view renders or depends on backing bean initialization?

    It can't depend on bean initialization. Without the view, JSF wouldn't have any idea which beans to initialize simply because those beans are declared in the view itself.