Apache MyFaces
Project Documentation
Foundation

Creating Custom Converters

A JSF Converter needs the following elements:

  • A class implementing converter interface.
  • Entry on faces-config.xml.
  • Tag entry on tld.
  • Tag entry on facelets taglib (optional).
  • JSP Tag class

Myfaces builder plugin provide annotations/doclets to help users maintain configuration files, and generating converter jsp tag classes automatically. In this way, all information for a converter is just in one file (the class implementing Converter interface).

On jsf 1.2, it is necessary to provide a base tag class that extends from javax.faces.webapp.ConverterELTag where all converters should inherit. This class is on myfaces commons converters project, but users can provide custom template implementations for it.

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 Converter Classes

Just add the annotations/doclets as presented below:

@JSFConverter(
    name = "mcc:convertDateTime",
    tagClass = "org.apache.myfaces.commons.converter.ConvertDateTimeTag",
    tagSuperclass = "org.apache.myfaces.commons.converter.ConverterTag")
public class DateTimeConverter extends javax.faces.convert.DateTimeConverter
{
    public static final String CONVERTER_ID = "org.apache.myfaces.custom.convertDateTime.DateTimeConverter";
 
    /** .......... impl code goes here ......... **/
    
    @JSFProperty
    public String getProperty()
    {
        // some stuff
    }   
}