Java Reference
In-Depth Information
The following are the valid values for the javax.faces.PROJECT_STAGE context
parameter for the faces servlet:
• 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 the 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 snippet above, we can implement the code to be executed in any
valid project stage, based on the return value of 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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
 
Search WWH ::




Custom Search