wicket.util.convert
Class MaskConverter

java.lang.Object
  extended by wicket.util.convert.LocalizableAdapter
      extended by wicket.util.convert.SimpleConverterAdapter
          extended by wicket.util.convert.MaskConverter
All Implemented Interfaces:
java.io.Serializable, IConverter, ILocalizable

public class MaskConverter
extends SimpleConverterAdapter

A converter that takes a mask into account. It is specifically meant for overrides on individual components, that provide their own converter by returning it from Component.getConverter(). It uses an instance of MaskFormatter to delegate the masking and unmasking to.

The following characters can be specified (adopted from the MaskFormatter documentation):

Character 

Description

# Any valid number, uses Character.isDigit.
' Escape character, used to escape any of the special formatting characters.
U Any character (Character.isLetter). All lowercase letters are mapped to upper case.
L Any character (Character.isLetter). All upper case letters are mapped to lower case.
A Any character or number (Character.isLetter or Character.isDigit)
? Any character (Character.isLetter).
* Anything.
H Any hex character (0-9, a-f or A-F).

Typically characters correspond to one char, but in certain languages this is not the case. The mask is on a per character basis, and will thus adjust to fit as many chars as are needed.

Author:
Eelco Hillenius
See Also:
MaskFormatter, Serialized Form

Constructor Summary
MaskConverter(javax.swing.text.MaskFormatter maskFormatter)
          Construct.
MaskConverter(java.lang.String mask, java.lang.Class type)
          Construct.
 
Method Summary
 java.lang.Object toObject(java.lang.String value)
          Converts a string to an object using MaskFormatter.stringToValue(String).
 java.lang.String toString(java.lang.Object value)
          Converts the value to a string using MaskFormatter.valueToString(Object).
 
Methods inherited from class wicket.util.convert.SimpleConverterAdapter
convert
 
Methods inherited from class wicket.util.convert.LocalizableAdapter
getLocale, setLocale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface wicket.util.convert.ILocalizable
getLocale, setLocale
 

Constructor Detail

MaskConverter

public MaskConverter(java.lang.String mask,
                     java.lang.Class type)
Construct.

Parameters:
mask - The mask to use for this converter instance
type - The type to convert string values to. WARNING: adding anything that implements charsequence here will probably not have the desired effect as then only toString(Object) will be called. Consider wrapping your string value in a custom class so that conversion will be triggered properly. That class should have a public constructor with a single string argument. That constructor will be used by MaskFormatter to construct instances.
See Also:
MaskFormatter

MaskConverter

public MaskConverter(javax.swing.text.MaskFormatter maskFormatter)
Construct. WARNING: setting DefaultFormatter.setValueClass(Class) to anything that implements charsequence, or not setting that class at all, which has the effect that String will be used will probably not have the desired effect as then only toString(Object) will be called. Consider wrapping your string value in a custom class so that conversion will be triggered properly. That class should have a public constructor with a single string argument. That constructor will be used by MaskFormatter to construct instances.

Parameters:
maskFormatter - The mask formatter to use for masking and unmasking values
Method Detail

toString

public java.lang.String toString(java.lang.Object value)
Converts the value to a string using MaskFormatter.valueToString(Object).

Specified by:
toString in class SimpleConverterAdapter
Parameters:
value - The value to convert, may be null
Returns:
The value as a string
See Also:
SimpleConverterAdapter.toString(java.lang.Object)

toObject

public java.lang.Object toObject(java.lang.String value)
Converts a string to an object using MaskFormatter.stringToValue(String).

Specified by:
toObject in class SimpleConverterAdapter
Parameters:
value - The string to convert, may be null
Returns:
The string value converted to an object of choice
See Also:
SimpleConverterAdapter.toObject(java.lang.String)


Copyright © 2004-2007 Wicket developers. All Rights Reserved.