Capturing State with a PhaseListener

An interesting use of the PhaseListener class we discussed in the previous section is to capture data about the request and all components in each phase and save the data where it can be picked up and displayed later. The captured data can be used to better understand what happens in the different phases and to figure out why things don’t work as expected.

I developed a PhaseListener that captures most data of interest, including the component tree structure, all component attributes and properties, and all variables in the request, session and application scopes, before and after each phase. Figure 12-8 shows an example of a response rendered by a servlet where you can analyze the captured data.

Analyzing captured data
Figure 12-8. Analyzing captured data

The data is displayed as a tree. The first level of the tree has one node for each point in the lifecycle. For each such node, there’s a node that holds the component tree and another that holds the scoped variables. You can compare a component’s property values in different phases and see when they change. For instance, if you look at an input component, you see how the submitted value migrates from the submittedValue property to the localValue and value properties.

I’ve commented out the registration elements for this listener in the example application’s faces-config.file because there’s a fair amount of processing ...

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.