Skip to main content

JSF Tip #48 - Use a custom packaged converter

Posted by mriem on November 27, 2013 at 11:44 AM PST

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>org.glassfish-samples.jsf</groupId>
            <artifactId>packagedCustomConverter</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>

Note the code for this sample is available as part of the Glassfish samples (see the subversion repository at https://svn.java.net/svn/glassfish-samples~svn/trunk/ws/javaee7/jsf/usePackagedCustomConverter/)

And that is it.

Enjoy!

Related Topics >>