How to configure JSF 2.0 application's project stage via JNDI in Tomcat

两盒软妹~` 提交于 2019-12-10 21:58:52

问题


been struggling to find a way to configure Tomcat 7.0.11 so that my web application would use project stage setting from Tomcat's config. So far - no luck. The idea is to set this property in Tomcat server/host/application wide but not to set it in web.xml. Any ideas? I am using MyFaces JSF 2 implementation 2.0.5.


回答1:


The specification says that the JSF implementation looks up the Project Stage using JNDI under java:comp/env/jsf/ProjectStage. If not found it uses the context parameter javax.faces.PROJECT_STAGE from your web.xml. This means that if defined/found on your Tomcat using JNDI, the value of preferred over the web.xml setting.

There are two things you can do:

Option 1: Overwrite the context parameter: This means that context parameter is set/overwritten using the Tomcat server.xml or context.xml. You need to put this in your <Context>-tag:

<Parameter name="javax.faces.PROJECT_STAGE" value="Production" override="false" />

Careful: override="false" here means that this parameter can NOT be overriden by the web.xml (not the other way around)!

Option 2: Configure a resource that can be found using JNDI: By using this that JSF implementation can resolve the project stage using the JNDI lookup.

<Environment name="jsf/ProjectStage" value="Production" type="java.lang.String" override="false"/>

You can also move this to the <GlobalResources>-tag in your server.xml. In this case you would need to reference this in your <Context>-tag by using <ResourceLink>-tag.



来源:https://stackoverflow.com/questions/6524901/how-to-configure-jsf-2-0-applications-project-stage-via-jndi-in-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!