Converting and validating a Social Security Number

How to get this to work in your own page

Insert the following snippets to get the JSF SSNConverter to work in your JSP page. Note since this is a converter it uses the converting tag to set itself up. Note more information about the SSNConverter can be found in the API documentation.

This demo requires you to enter a SSN, if you do not enter a SSN it will show you an error. If you enter some values for the SSN it will call the validator to validate the SSN. The input field here requires you to enter the SSN, and if you add it with dashes it will silently ignore those. The converter will make sure it gets converted properly.

    <%@taglib prefix="ssn" uri="http://www.manorrock.com/tld/jsf/ssn"%>

    <h:inputText required="true" requiredMessage="SSN is required" value="#{ssnBean.ssn}">
        <f:validator validatorId="com.manorrock.jsf.ssn.validator.SSNValidator"/>
        <f:converter converterId="com.manorrock.jsf.ssn.converter.SSNConverter"/>
    </h:inputText>

    

Actual demo

Enter a SSN: