- 

Available since OmniFaces 2.2

The CDI annotation @ContextParam allows you to inject a web.xml context parameter from the current application in a CDI managed bean. It's basically like @ManagedProperty("#{initParam['some.key']}") private String someKey; in a "plain old" Faces managed bean.

By default the name of the context parameter is taken from the name of the variable into which injection takes place. The example below injects the context parameter with name foo.

@Inject @ContextParam
private String foo;

The name can be optionally specified via the name attribute, which shall more often be used as context parameters may have a.o. periods and/or hyphens in the name, which are illegal in variable names. The example below injects the context parameter with name foo.bar into a variable named bar.

@Inject @ContextParm(name="foo.bar")
private String bar;
Demo

Injected context params:

  • jakarta.faces.FACELETS_BUFFER_SIZE = 65535
  • jakarta.faces.FACELETS_LIBRARIES = /WEB-INF/showcase.taglib.xml
  • jakarta.faces.FACELETS_SKIP_COMMENTS = true
Demo source code
<p>Injected context params:</p>
<ul>
    <li><code>jakarta.faces.FACELETS_BUFFER_SIZE</code> = <code>#{cdiContextParamBean.faceletsBufferSize}</code></li>
    <li><code>jakarta.faces.FACELETS_LIBRARIES</code> = <code>#{cdiContextParamBean.faceletsLibraries}</code></li>
    <li><code>jakarta.faces.FACELETS_SKIP_COMMENTS</code> = <code>#{cdiContextParamBean.faceletsSkipComments}</code></li>
</ul>