Skip to Content
JavaServer Faces
book

JavaServer Faces

by Hans Bergsten
April 2004
Intermediate to advanced
606 pages
20h 4m
English
O'Reilly Media, Inc.
Content preview from JavaServer Faces

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.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Mastering JavaServer Faces 2.2

Mastering JavaServer Faces 2.2

Anghel Leonard

Publisher Resources

ISBN: 0596005393Errata Page