barcode visual basic Using a PhaseListener to Observe the Faces Lifecycle in Action in Java

Maker QR Code 2d barcode in Java Using a PhaseListener to Observe the Faces Lifecycle in Action

Using a PhaseListener to Observe the Faces Lifecycle in Action
QR Code 2d Barcode Drawer In Java
Using Barcode creator for Java Control to generate, create Quick Response Code image in Java applications.
Decode QR Code 2d Barcode In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
One of the most useful things to do is to write a phase listener that executes at every phase in the Faces lifecycle and reports to either a logging facility (or even just to the console) when the different phases of the lifecycle are processed This type of phase listener is very easy to write, and it can be used as a tool to confirm the correct execution of events and phases based on different criteria, such as when certain UI components have their immediate property set to true, or if a certain listener method short-circuits the lifecycle directly by calling the RenderResponse( ) method of the Faces context To build a phase listener to process the phase events that are emitted by the changing of lifecycle phases, simply create a Java class that implements the PhaseListener interface We begin by creating the following skeleton, called MyPhaseListener:
Barcode Printer In Java
Using Barcode printer for Java Control to generate, create bar code image in Java applications.
Decode Barcode In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
package comjsfcompref; import javaxfaceseventPhaseListener; public class MyPhaseListener implements PhaseListener { public MyPhaseListener() { } // Implement PhaseListener methods here }
Quick Response Code Creation In Visual C#.NET
Using Barcode printer for Visual Studio .NET Control to generate, create QR-Code image in Visual Studio .NET applications.
Paint Quick Response Code In .NET Framework
Using Barcode encoder for ASP.NET Control to generate, create QR-Code image in ASP.NET applications.
Part I:
Generate QR-Code In Visual Studio .NET
Using Barcode drawer for .NET Control to generate, create QR-Code image in .NET framework applications.
QR Code Generation In Visual Basic .NET
Using Barcode printer for Visual Studio .NET Control to generate, create QR Code ISO/IEC18004 image in .NET framework applications.
The JavaServer Faces Framework
EAN / UCC - 14 Creation In Java
Using Barcode creator for Java Control to generate, create GTIN - 128 image in Java applications.
Generating GS1 128 In Java
Using Barcode maker for Java Control to generate, create EAN128 image in Java applications.
Next, the methods beforePhase( ), afterPhase( ), and getPhaseId( ) must be overridden and implemented Both the beforePhase( ) and afterPhase( ) methods accept a single argument of type PhaseEvent and execute either before or after the phase event is passed to the methods Each phase event has an associated phase ID and can be used to pick when to execute the method Since the beforePhase( ) and afterPhase( ) methods execute for all phase events, if you want to perform a specific action for a single phase of the lifecycle, you can provide some simple logic to check the phase ID of the incoming phase event and then conditionally execute your code based on that check For example, the following beforePhase( ) method will print a message Processing new Request! to the console, but only when it processes a RESTORE_VIEW phase event The subsequent statement will print a message before - phase id for all phase events of the lifecycle:
GS1 DataBar Limited Creation In Java
Using Barcode generator for Java Control to generate, create GS1 DataBar Limited image in Java applications.
Bar Code Generation In Java
Using Barcode creator for Java Control to generate, create barcode image in Java applications.
public void beforePhase(PhaseEvent pe) { if (pegetPhaseId() == PhaseIdRESTORE_VIEW) { Systemoutprintln("Processing new Request!"); } Systemoutprintln("before - " + pegetPhaseId()toString()); }
UPC-E Supplement 5 Generator In Java
Using Barcode generation for Java Control to generate, create UPC-E Supplement 5 image in Java applications.
Data Matrix ECC200 Encoder In None
Using Barcode generator for Excel Control to generate, create Data Matrix 2d barcode image in Microsoft Excel applications.
A subsequent afterPhase( ) method can be similarly coded as
Code 128 Code Set A Reader In Visual Basic .NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
Creating GS1 DataBar Stacked In .NET Framework
Using Barcode printer for .NET Control to generate, create GS1 RSS image in Visual Studio .NET applications.
public void afterPhase(PhaseEvent pe) { Systemoutprintln("after - " + pegetPhaseId()toString()); if (pegetPhaseId() == PhaseIdRENDER_RESPONSE) { Systemoutprintln("Done with Request!\n"); } }
Draw ANSI/AIM Code 39 In Java
Using Barcode maker for BIRT Control to generate, create Code 3/9 image in Eclipse BIRT applications.
Data Matrix ECC200 Drawer In None
Using Barcode creation for Software Control to generate, create ECC200 image in Software applications.
Notice how this method prints an after phase message for all phases It also prints a special Done with Request! when it encounters the final Render Response phase The final method to implement is getPhaseId( ), which is used to determine which phase this phase listener will process events for Since it must execute during every phase change, it returns ANY_PHASE
Bar Code Scanner In .NET Framework
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in .NET applications.
Create Linear 1D Barcode In Visual Basic .NET
Using Barcode printer for .NET Control to generate, create 1D Barcode image in VS .NET applications.
public PhaseId getPhaseId() { return PhaseIdANY_PHASE; }
The code to the phase listener is now complete, but to use it in the Faces application, its full classpath must be registered One way is to specify it in the faces-configxml as follows:
<lifecycle> <phase-listener>comjsfcomprefMyPhaseListener</phase-listener> </lifecycle>
TIP Beginning with Faces 12, it is also possible to register phase listeners directly on the
UIViewRoot and avoid the necessity of including them in the faces-configxml file
9:
The JSF Event Model
Once registered in a Faces application, the phase listener will report all of the lifecycle phases being entered during execution of the application For example, upon an initial, nonpostback request to a Faces application, the output in the console will look like this:
Processing new Request! before - RESTORE_VIEW 1 after - RESTORE_VIEW 1 before - RENDER_RESPONSE 6 after - RENDER_RESPONSE 6 Done with Request!
PARTIII PART PART
The text in boldface is what is returned from getPhaseId()toString() This confirms what was presented in 3 in that during an initial Faces request, where no data is being posted back to the application, the request processing lifecycle simply creates a new view of UI components (in the Restore View phase) and then renders a response to the client A subsequent request that now posts form information back to the application will cause the following output, since the entire lifecycle will be processed
Processing new Request! before - RESTORE_VIEW 1 after - RESTORE_VIEW 1 before - APPLY_REQUEST_VALUES 2 after - APPLY_REQUEST_VALUES 2 before - PROCESS_VALIDATIONS 3 after - PROCESS_VALIDATIONS 3 before - UPDATE_MODEL_VALUES 4 after - UPDATE_MODEL_VALUES 4 before - INVOKE_APPLICATION 5 after - INVOKE_APPLICATION 5 before - RENDER_RESPONSE 6 after - RENDER_RESPONSE 6 Done with Request!
Once a phase listener like this has been installed, you can observe the effects of several changes that can affect the processing order of the Faces lifecycle For example, a page with a single commandButton that is bound to an action method, which prints out a message in action method, could have its immediate property set to true When the application is run, it will execute the action method at the end of the Apply Request Values phase, as opposed to the Invoke Application phase, where it would normally execute, as shown next:
Processing new Request! before - RESTORE_VIEW 1 after - RESTORE_VIEW 1 before - APPLY_REQUEST_VALUES 2 Action event processed after - APPLY_REQUEST_VALUES 2 before - RENDER_RESPONSE 6 after - RENDER_RESPONSE 6 Done with Request!
Part I:
Copyright © OnBarcode.com . All rights reserved.