开发者

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

[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 PRO开发者_开发百科JECT_STAGE value inside my application?


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()


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


You can get it using initParam pre-defined JSF EL variable

#{initParam['javax.faces.PROJECT_STAGE']}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜