JSF Tip #48 - Use a custom packaged converter

In the previous blog entry we touched upon packaging a custom converter. Now we'll describe what you need to do to use it.

Add the maven dependency to your project.


    <dependency>
        <groupId>myGroupId</groupId>
        <artifactId>myPackagedCustomConverter</artifactId>
        <version>${project.version}</version>
    </dependency>
        

And use it.


    <?xml version='1.0' encoding='UTF-8'?>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core">
        <h:head>
            <title>Custom Converter - f:converter tag</title>
        </h:head>
        <h:body>
            <h2>Custom Converter - f:converter tag</h2>
            <p>
                Below you will see a string that was generated using a custom converter
                named 'customConverterId'. See the sources for the source for this
                converter.
            </p>
            <h:outputText value="#{customConverterBean.custom}">
                <f:converter converterId="customConverterId"/>
            </h:outputText>
        </h:body>
    </html>
        

Posted November 26, 2013

Up