• cdi
  • components
  • contexts
  • converters
  • el
  • eventlisteners
  • exceptionhandlers
  • facesviews
  • filters
  • functions
  • managedbeans
  • push
  • resourcehandlers
  • scripts
  • servlets
  • taghandlers
  • utils
  • validators
  • viewhandlers
  • ContextParam
  • Cookie
  • Eager
  • FacesConverter
  • FacesValidator
  • GraphicImageBean
  • Param
  • ViewScoped

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" JSF 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;

Injected context params:

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