3

To create a custom component in JSF, it is necesary create a class that extends UIComponent and register its component type in JSF,using for example @FacesComponent. To use this component and its attributes in a facelets page, it is necesary link the component with the facelets tag in a special file called tag description file:

<tag> <tag-name>test</tag-name> <component> <component-type>local.test.component_type</component-type> </component> </tag> 

Ok, but I'm confused with the use of tag classes (and tag handlers). Looking at mojarra source code, all html basic components are declared in the tag library description file using a component tag class that extends UIComponentELTag. For example:

<tag> <name>commandButton</name> <tag-class> com.sun.faces.taglib.html_basic.CommandButtonTag </tag-class> </tag> 

Looking at JSF api of UIComponentELTag:

UIComponentELTag specializes its superclass to allow for properties that take their values from EL API expressions.

This tag is designed for use with Faces version 1.2 and JSP version 2.1 containers.

Then the question is, when I should use a class that extends a UIComponentELTag to link the tag attributes with the custom component instead of to link the component through ? If I don't use a tag class, then my comonent cannot be used in JSP pages or previous JSF versions and only will work in JSF facelets?

1 Answer 1

2

If I don't use a tag class, then my comonent cannot be used in JSP pages or previous JSF versions and only will work in JSF facelets?

That's correct. If you don't use a tag class for your JSF 2.0 custom component, then your JSF 2.0 custom component is not compatible with JSP in any way and also not with JSF 1.2 or older. JSP has been deprecated since JSF 2.0, so unless you absolutely need to support JSP and/or JSF 1.2, you do not need to create a tag class at all. This saves you from unnecessary boilerplate code. Some JSF 2.0 component libraries like PrimeFaces even don't support JSP at all.

Tag handlers are a different story. Tag handlers are not the same as tag classes for UI components. To understand what tag handlers are, look at the JSF core (<f:xxx>) tag library. All the standard JSF tag handlers are in there. They are still useful in JSF 2.0. With tag handlers you can control the way how the JSF view is been built (with UI components you can control how the JSF view is been rendered).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.