Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access javax.faces.PROJECT_STAGE from the view/inside code?

Tags:

java

jsf

jsf-2

[My Setup: Java EE 6 application, with EJB3.1, CDI/Weld, JSF2 running on Glassfish 3.0.1]

I just read about the Faces ProjectStage on this page, which is a cool thing. So i configured it in my Web.xml, setting it to Development:

<context-param>
  <param-name>javax.faces.PROJECT_STAGE</param-name>   
  <param-value>Development</param-value>
</context-param>

Now i want to access the ProjectStage from the JSF view (setting the visibility of specific UI components accordingly).

Therefore i already tried things like an outputtext with the value #{javax.application.projectStage}, which seems to be null, and i also tried many other variants, with no success. I even don't manage to access the ProjectStage from within Java code (then i could expose it myself with a Bean).

How can i access the PROJECT_STAGE value inside my application?

like image 989
Wolkenarchitekt Avatar asked Aug 03 '10 15:08

Wolkenarchitekt


2 Answers

Got it. From the view, it can be accessed like:

<h:outputText value="Stage:#{facesContext.application.projectStage}"/>

In the code, it can be accessed like:

FacesContext.getCurrentInstance().getApplication().getProjectStage().toString()
like image 134
Wolkenarchitekt Avatar answered Oct 05 '22 07:10

Wolkenarchitekt


This is probably exposed via the initParam implicit object. Failing that, check the ExternalContext.

like image 26
McDowell Avatar answered Oct 05 '22 07:10

McDowell