- java.lang.Object
-
- jakarta.faces.view.facelets.TagHandler
-
- org.omnifaces.taghandler.TagAttribute
-
- All Implemented Interfaces:
FaceletHandler
public class TagAttribute extends TagHandler
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.Consider the following custom tag structure:
<my:tag id="foo"> <my:tag id="bar" /> </my:tag>
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 /> </my:tag>
then
#{id}
of the nested tag would evaluate to"foo"
instead ofnull
, 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.
Usage
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" />
Since OmniFaces 2.7/3.2 there is a special case for a<o:tagAttribute name="id">
without a default value: it will override any autogenerated ID into the form ofj_ido[tagId]
where[tagId]
is the<o:tagAttribute>
tag's own unique ID.- Since:
- 2.1
- Author:
- Arjan Tijms.
-
-
Field Summary
-
Fields inherited from class jakarta.faces.view.facelets.TagHandler
nextHandler, tag, tagId
-
-
Constructor Summary
Constructors Constructor Description TagAttribute(TagConfig config)
The tag constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
apply(FaceletContext context, UIComponent parent)
-
Methods inherited from class jakarta.faces.view.facelets.TagHandler
getAttribute, getRequiredAttribute, toString
-
-
-
-
Constructor Detail
-
TagAttribute
public TagAttribute(TagConfig config)
The tag constructor.- Parameters:
config
- The tag config.
-
-
Method Detail
-
apply
public void apply(FaceletContext context, UIComponent parent) throws IOException
- Throws:
IOException
-
-