Time for action – using the custom JSF converter on the client side
Let us see how we can create a custom JSF converter and use it with the PrimeFaces CSV framework, by performing the following steps:
- Create a bean named
CreditCardBean
:public class CreditCardBean { private String number; public CreditCardBean(String number) { this.number = number; } public String toString() { return number; } }
- Create the
CreditCardConverter
class to convert a string value into theCreditCardBean
object and vice versa by implementingjavax.faces.convert.Converter
andorg.primefaces.convert.ClientConverter
:@FacesConverter("creditCardConverter") public class CreditCardConverter implements Converter, ClientConverter { private static final String CC_PATTERN = "^\\d{4} \\d{4} \\d{4} \\d{4}$"; @Override public Object getAsObject(FacesContext context, UIComponent component, String value) { if (value==null || value...