Storing View ID in JSF
I want to understand how JSF is storing the view and restoring the view. I have read that it is creating the separate view id for each view and storing it on the server. Then it retrieves. The following are my questions:
- In what basis view id is created and stored?
- Is it created based on the JSP's declared on the faces-config.xml?
- Basically is it created for the each JSP one view I开发者_Go百科D?
- How view ids are passed to render the response? Is it passed in the request parameter?
In what basis view id is created and stored?
The view ID is the context relative path of the view file. E.g. /foo.jsp
or /foo.xhtml
. The ViewHandler
implementation is responsible for creating it and storing it in UIViewRoot
.
Is it created based on the JSP's declared on the faces-config.xml?
Those doesn't necessarily need to be declared anywhere in faces-config.xml
. For every incoming request, it's extracted from the request URI by the underlying HttpServletRequest
object by its getPathInfo()
or getServletPath()
methods, depending on whether the FacesServlet
itself is mapped with prefix pattern (/faces/*
) or suffix pattern (*.jsf
) respectively.
When JSF needs to navigate to a new view as per a <navigation-case>
in faces-config.xml
, then the new view ID is simply extracted from it and a new UIViewRoot
is created by end of invoke action phase. Otherwise JSF just goes back to the same view as the request was originated.
Basically is it created for the each JSP one view ID?
Yes, every view has its own unique identifier, which is basically just its location in the webapplication context.
How view ids are passed to render the response? Is it passed in the request parameter?
They are stored in UIViewRoot
which is in turn just available by FacesContext#getViewRoot()
. The ViewHandler
implementation just calls getViewId()
during the renderView()
method.
精彩评论