The ViewHandler Class
The javax.faces.application.ViewHandler
class
is responsible for making JSF views available to the rest of the JSF
framework. It’s a fairly simple class, with three
primary methods: createView()
,
renderView()
, and restoreView(
)
.
The createView()
method
creates a component tree corresponding to a
view identifier with at least a UIViewRoot
component as the root, and returns it initialized with render kit and
locale information. The renderView()
method
renders the specified view and saves the view state, and the
restoreView()
method restores a view from the
saved state information. Both of these methods cooperate with a
javax.faces.application.StateManager
for handling
the details about how and where the view state is saved. A custom
ViewHandler
can support pretty much any type of
view representation by implementing these three methods.
Declare that an application uses a custom
ViewHandler
in the
faces-config.xml file:
<faces-config> ... <application> <view-handler> com.mycompany.jsf.pl.ClassViewHandlerImpl </view-handler> </application> ... </faces-config>
Because only one ViewHandler
can be used at a
time, I have commented out the declarations for the custom handlers
we develop in this chapter in the book examples
faces-config.xml file. To run the examples from
this chapter, you must first remove the comments around one
declaration at a time and restart the web container.
Get JavaServer Faces now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.