org.apache.cocoon.faces.samples.carstore
Class CreditCardConverter

java.lang.Object
  extended by org.apache.cocoon.faces.samples.carstore.CreditCardConverter
All Implemented Interfaces:
javax.faces.convert.Converter

public class CreditCardConverter
extends Object
implements javax.faces.convert.Converter

CreditCardConverter Class accepts a Credit Card Number of type String and strips blanks and "-" if any from it. It also formats the CreditCardNumber such a blank space separates every four characters. Blanks and "-" characters are the expected demiliters that could be used as part of a CreditCardNumber.


Field Summary
static String CONVERSION_ERROR_MESSAGE_ID
          The message identifier of the Message to be created if the conversion fails.
 
Constructor Summary
CreditCardConverter()
           
 
Method Summary
 Object getAsObject(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, String newValue)
          Parses the CreditCardNumber and strips any blanks or "-" characters from it.
 String getAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)
          Formats the value by inserting space after every four characters for better readability if they don't already exist.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONVERSION_ERROR_MESSAGE_ID

public static final String CONVERSION_ERROR_MESSAGE_ID

The message identifier of the Message to be created if the conversion fails. The message format string for this message may optionally include a {0} and {1} placeholders, which will be replaced by the object and value.

See Also:
Constant Field Values
Constructor Detail

CreditCardConverter

public CreditCardConverter()
Method Detail

getAsObject

public Object getAsObject(javax.faces.context.FacesContext context,
                          javax.faces.component.UIComponent component,
                          String newValue)
                   throws javax.faces.convert.ConverterException
Parses the CreditCardNumber and strips any blanks or "-" characters from it.

Specified by:
getAsObject in interface javax.faces.convert.Converter
Throws:
javax.faces.convert.ConverterException

getAsString

public String getAsString(javax.faces.context.FacesContext context,
                          javax.faces.component.UIComponent component,
                          Object value)
                   throws javax.faces.convert.ConverterException
Formats the value by inserting space after every four characters for better readability if they don't already exist. In the process converts any "-" characters into blanks for consistency.

Specified by:
getAsString in interface javax.faces.convert.Converter
Throws:
javax.faces.convert.ConverterException


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.