HTML and CSS Reference
In-Depth Information
public class AuthorizationListener implements PhaseListener {
public void afterPhase(PhaseEvent event) {
FacesContext context = event.getFacesContext();
NavigationHandler navigationHandler = context.getApplication().getNavigationHandler();
String currentPage = context.getViewRoot().getViewId();
boolean isProtectedPage = currentPage.contains("/protected/");
//Restrict access to protected pages ...
if (isProtectedPage) {
navigationHandler.handleNavigation(context, null, "/home?faces-redirect=true");
public void beforePhase(PhaseEvent event) {
//Nothing ...
public PhaseId getPhaseId() {
return PhaseId.RESTORE_VIEW;
AuthorizationListener phase listener prohibits any user from accessing the pages in the protected
folder directly.
In the next section, we will go through the registration pages in order to understand how to utilize the JSF 2.2
Faces Flow in order to implement the registration flow behavior in our weather application.
Leveraging Faces Flow
As you know from Chapter 5, Faces Flow is introduced in JSF 2.2 to enable flow management in JSF applications.
In the old days, in order to implement flows in JSF applications, the JSF developer has either to use additional
frameworks such as Spring Web Flow or ADF Task Flows or to implement it manually using the HTTP session.
Implementing it manually using the HTTP session is not an efficient way of implementation because the JSF
developer will have to handle the session cleanup after the flow is completed or exited.
In JSF Faces Flow, the developer can define a flow on a set of related pages (or views or nodes) with well-defined
entry and exit points. In the weather application, we package the Flow pages in a single directory ( /registration ) to
be convenient with the JSF flow convention rules, which are as follows:
Every XHTML file in the flow directory acts as a view node of the flow.
The start node of the flow is the view whose name is the same as the name of the flow
( registration.xhtml ).
Navigation between the pages in the flow directory is considered a navigation within
the flow.
Navigation to a view outside the flow directory is considered an exit from the flow.
Search WWH ::

Custom Search