简体   繁体   中英

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 ID?
  • 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. Eg /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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM