Home > Java > Externalize JSF project stage

Externalize JSF project stage

Java ServerFaces (JSF) has a configuration option that should be set to Development in development and Production in production:


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

Unfortunately it is defined in web.xml, so the binary file installed in development must differ from the binary file in production. Find and replace at build time works, but it is cumbersome and prone to errors.

The ideal solution would be to use system properties, but JSF does not support that. However, JSF can use JNDI lookups! Why they would support something as complex as JNDI in place of something as simple and straightforward as system properties beats me, but there you are.

To use a JNDI lookup, add the following to web.xml instead of the context parameter:


<resource-ref>
  <res-ref-name>jsf/ProjectStage</res-ref-name>
  <res-type>java.lang.String</res-type>
  <lookup-name>JsfProjectStage</lookup-name>
</resource-ref>

The lookup name can be defined in the application server. If it is missing JSF will warn, but defaults to production mode.

Advertisements
Categories: Java
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: