SeamFramework.orgCommunity Documentation
The Seam Faces module provides integration with the JSF project stage system. Beside the injection of the current project stage into beans, Seam Faces also allows to enable specific beans only for certain project stages.
Seam Faces supports the injection of the current project stage directly into CDI managed beans. This allows to implement special behavior for certain project stages very easily.
public class Bean {
@Inject
private ProjectStage projectStage;
public void someMethod() {
if (projectStage == ProjectStage.Development) {
/* do something special for development mode here */
}
}
}
Seam Faces provides a set of annotations that can be used to activate beans only in specific project stages. The following table shows the JSF project stages and the corresponding Seam Faces annotations.
Project Stage | ProjectStage Enum | Seam Faces Anntotation |
---|---|---|
Production | ProjectStage.Production | @Production |
Development | ProjectStage.Development | @Development |
UnitTest | ProjectStage.UnitTest | @UnitTest |
SystemTest | ProjectStage.SystemTest | @SystemTest |
To restrict a bean to a project stage just place the correspoding annotation on the class.
The following example shows a bean that logs the beginning and end of each JSF lifecycle phase.
As the bean is annotated with @Development
, it will only be activated
if the application runs in the Development
project stage.
@Development
public class PhaseEventLogBean {
public void before(@Observes @Before PhaseEvent event) {
log.debug("Before: " + event.getPhaseId());
}
public void after(@Observes @After PhaseEvent event) {
log.debug("After: " + event.getPhaseId());
}
}
You can place more than one project stage annotation on a bean. So if a bean should be active in all
project stages except for Production
, define it like this:
</span> <!-- --><br/><span class="java_plain">@</span><span class="java_type">Development</span><span class="java_plain"> @</span><span class="java_type">SystemTest</span><span class="java_plain"> @</span><span class="java_type">UnitTest</span> <!-- --><br/><span class="java_keyword">public</span><span class="java_plain"> </span><span class="java_keyword">class</span><span class="java_plain"> </span><span class="java_type">Bean</span><span class="java_plain"> </span><span class="java_separator">{</span> </span> <!-- --><br/><span class="java_separator">}</span> <!-- --><br/><span class="java_plain"> </span>
Seam Faces will automatically detect the project stage that is used for the application. If you want Seam Faces to use a different project stage, you can use one of the following two ways.
The first possibility to change the project stage for Seam Faces is to set the system property
org.jboss.seam.faces.PROJECT_STAGE
. This option is the most easiest to use but
is also very unflexible because the project stage be set for all applications running in a container.
-Dorg.jboss.seam.faces.PROJECT_STAGE=Development
If you need more control over the project stage that is used you can implement the Seam Faces
SPI org.jboss.seam.faces.projectstage.ProjectStageDetector
. Just implement
this interface and add the fully-qualified classname of the class to the file
META-INF/services/org.jboss.seam.faces.projectstage.ProjectStageDetector
.
See the following class for an example:
public class MyProjectStageDetector implements ProjectStageDetector {
@Override
public int getPrecedence() {
return 10;
}
@Override
public ProjectStage getProjectStage() {
if (System.getProperty("user.name").startsWith("dev-")) {
return ProjectStage.Development;
}
return ProjectStage.Production;
}
}