Apache MyFaces
Project Documentation
Foundation

Creating Custom JSF Tags

A JSF Tag needs the following elements:

  • JSP Tag class.
  • Tag entry on tld.
  • Facelets Tag Handler class (optional).
  • Tag entry on facelets taglib (optional).

Myfaces builder plugin provide annotations/doclets to help users maintain configuration files. In this way, all information for a tag is just in one file.

Any tag is registered on facelets taglib if it has a related tag handler. Usually, custom tag classes should have facelets tag handlers with similar functions, but on facelets world there is no need to define properties on a xml file.

Setting up your project

All information related can be found here.

Configuration files (faces-config.xml, .tld, facelets taglib)

This page shows some examples.

Annotate JSF Tag Classes

Just add the annotations/doclets as presented below:

@JSFJspTag(
    name = "f:valueChangeListener",
    bodyContent = "empty")
public class ValueChangeListenerTag extends 
    GenericListenerTag<EditableValueHolder, ValueChangeListener>
{

    /** ............. some code goes here ................. **/
    
    @Override
    @JSFJspAttribute(
        className = "java.lang.String",
        rtexprvalue = true)
    public void setType(ValueExpression type)
    {
        super.setType(type);
    }

    @Override
    @JSFJspAttribute(
        className = "javax.faces.event.ValueChangeListener",
        rtexprvalue = true)
    public void setBinding(ValueExpression binding)
    {
        super.setBinding(binding);
    }
}