2

I need to change the value of the project stage dynamically ( at runtime ), based on the environment, using JNDI. From what I understand, the JNDI will override what is defined in web.xml. Is there a document / link that will help me with how I should code it? I am using websphere 8.5

In some examples I have seen that it is defined as resource-ref, but I am not sure I understand how is that used with JNDI to make it work and change the value at runtime.

Can someone help me with this?

adbdkb
  • 1,897
  • 6
  • 37
  • 66
  • What is 'project stage'? What exact piece of configuration do you want to manage through JNDI? – ᄂ ᄀ Jul 12 '14 at 11:45
  • [This link](https://blogs.oracle.com/rlubke/entry/jsf_2_0_new_feature2) explains project stage much better than I can attempt to. I want to make sure that in production, it will be "Production". When using the web.xml context-param, many applications are getting moved with the value of "Development". – adbdkb Jul 12 '14 at 12:34

1 Answers1

1

As JSF 2.0 spec states, you can override context parameter javax.faces.PROJECT_STAGE via JNDI entry, which is looked via reference java:comp/env/jsf/ProjectStage.

To override the context parameter, you need to define following resource environment reference in your web.xml file:

<resource-env-ref>
   <description />
   <resource-env-ref-name>jsf/ProjectStage</resource-env-ref-name>
   <resource-env-ref-type>java.lang.String</resource-env-ref-type>
</resource-env-ref>

in the application server configuration, you can define your ProjectStage value via Namespace binding ( in the web admin console select Environment > Name Space Bindings, define new String variable with jndi name jsf/ProjectStage and value Development or Production, depending on the environment).

Finally you need to bind your reference in the project with variable in JNDI. You can do it it 2 ways, via ibm-web-bnd.xml file, defining:

<resource-ref name="jsf/ProjectStage" binding-name="jsf/ProjectStage" />

Or during application installation, in the step were you provide mappings for Resource environment references.

For detailed discussion on this topic check Dynamically change project stage value at runtime using JNDI

Gas
  • 17,601
  • 4
  • 46
  • 93
  • Thank you, Gas. I am the same person who asked that question on dW because I didn't get an answer here. :) I really appreciate the help you and Brian provided me in getting this resolved and I also now understand the difference between resource-ref and resource-env-ref. – adbdkb Jul 20 '14 at 22:05
  • You're welcome. I suspected that :-). I just created brief version here, so others could find it easier also. – Gas Jul 20 '14 at 22:08
  • Thank you. It was good that you answered it, so there is a description here. I was just going to add the link to dW post so that others would find it. But now, they have the answer right here as well. – adbdkb Jul 20 '14 at 22:11