Java Reference
In-Depth Information
The valid values for the javax.faces.PROJECT_STAGE context parameter for the
faces servlet are as follows:
Development
Production
SystemTest
UnitTest
As we previously mentioned, the Development project stage adds additional
debugging information to ease development. The Production project stage focuses
on performance. The other two valid values for the project stage ( SystemTest and
UnitTest ) allow us to implement our own custom behavior for these two phases.
The javax.faces.application.Application class has a getProjectStage()
method that allows us to obtain the current project stage. Based on the value of this
method, we can implement code that will only be executed in the appropriate stage.
The following code snippet illustrates this:
public void someMethod() {
FacesContext facesContext = FacesContext.getCurrentInstance();
Application application = facesContext.getApplication();
ProjectStage projectStage = application.getProjectStage();
if (projectStage.equals(ProjectStage.Development)) {
//do development stuff
} else if (projectStage.equals(ProjectStage.Production)) {
//do production stuff
} else if (projectStage.equals(ProjectStage.SystemTest)) {
// do system test stuff
} else if (projectStage.equals(ProjectStage.UnitTest)) {
//do unit test stuff
}
}
As illustrated in the preceding snippet, we can implement code to be executed in any
valid project stage, based on the value returned by the getProjectStage() method
of the Application class.
When creating a Java web project using JSF, a facelet is automatically generated.
The generated facelet file looks like this:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
Search WWH ::




Custom Search