• cdi
  • components
  • contexts
  • converters
  • el
  • eventlisteners
  • exceptionhandlers
  • facesviews
  • filters
  • functions
  • managedbeans
  • push
  • resourcehandlers
  • servlets
  • taghandlers
  • utils
  • validators
  • viewhandlers
  • converter
  • enableRestorableView
  • ignoreValidationFailed
  • importFunctions
  • massAttribute
  • methodParam
  • skipValidators
  • tagAttribute
  • validator
  • viewParamValidationFailed

Available since OmniFaces 2.1

The <o:tagAttribute> is a tag handler that can be used to explicitly declare a tag attribute on a Facelets tag file. This makes sure that any tag attribute with the same name on a parent tag file is cleared out, which does not properly happen in Mojarra. This tag handler is designed to be used only in Mojarra and does not work in MyFaces as it has already internally solved this problem.

Consider the following custom tag structure:

<my:tag id="foo">
    <my:tag id="bar" />

Inside the nested tag, the #{id} will just evaluate to "bar". However, if this isn't declared on the nested tag like so,

<my:tag id="foo">
    <my:tag />

then #{id} would evaluate to "foo" instead of null, even when you explicitly specify the attribute in the *.taglib.xml file.

This tag handler is designed to overcome this peculiar problem and unintuitive behavior of nested tagfiles in Mojarra.


Just declare the attribute name in top of the tagfile as below.

<o:tagAttribute name="id" />

You can optionally provide a default value.

<o:tagAttribute name="type" default="text" />


MyFaces has already internally solved this problem. Using <o:tagAttribute> in MyFaces will break tag attributes. Do not use it in MyFaces. In case you intend to solely have a default value for a tag attribute, then continue using JSTL for that.

<c:set var="type" value="#{empty type ? 'text' : type}" />