carstore
Class CreditCardConverter

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

public class CreditCardConverter
extends java.lang.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 java.lang.String CONVERSION_ERROR_MESSAGE_ID
          The message identifier of the Message to be created if the conversion fails.
 
Constructor Summary
CreditCardConverter()
           
 
Method Summary
 java.lang.Object getAsObject(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String newValue)
          Parses the credit card number and strips any whitespace or "-" characters from it.
 java.lang.String getAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.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 java.lang.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 java.lang.Object getAsObject(javax.faces.context.FacesContext context,
                                    javax.faces.component.UIComponent component,
                                    java.lang.String newValue)
                             throws javax.faces.convert.ConverterException

Parses the credit card number and strips any whitespace or "-" characters from it.

Specified by:
getAsObject in interface javax.faces.convert.Converter
Parameters:
context - the FacesContext of the current request
component - the component associated with the value
newValue - the new value
Returns:
the credit card number less any whitespace or "-" characters
Throws:
javax.faces.convert.ConverterException - if the value cannot be converted

getAsString

public java.lang.String getAsString(javax.faces.context.FacesContext context,
                                    javax.faces.component.UIComponent component,
                                    java.lang.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
Parameters:
context - the FacesContext of the current request
component - the component associated with the value
value - the value to convert
Returns:
a formatted credit card number
Throws:
javax.faces.convert.ConverterException - if the value cannot be converted


Copyright © 2004 Sun Microsystems, Inc. All Rights Reserved.