Converter question
I would like to store phone numbers as text in a database without any formatting. That is, if a user enters 111-222-3333 or (111)222-3333 or even 111 222 3333, the number would be stored as 1112223333. The idea is to allow the user enter phone numbers any way he wants, as long as it contains 10 numbers. (I defined a validator to make sure of that.)
When a phone number is retrieved from the database, I want to format it before displaying it. So 1112223333 would be displayed as 111-222-3333.
I thought a converter would do exactly that, but that doesn't appear to be the case.
Here's my understanding of what a converter does:
1. getAsObject takes the contents of, say a text field or static text, and returns an object that represents the internal data representation.
In my case, the input is a phone number entered by a user and the output is the phone number with all formatting removed.
2. getAsString takes the internal data representation and returns a String that represents the value displayed in say a text field or static text.
In my case, the input is a phone number without formatting and the output is a phone number with formatting.
I created a converter whose getAsObject returns a String without formatting and whose getAsString returns a String with formatting. That didn't work.
So I created another converter whose getAsObject returns a StringValue object. StirngValue is just a wrapper for a String.
publicclass StringValue{
public StringValue(){
}
private String value;
public String getValue(){
return this.value;
}
publicvoid setValue(String value){
this.value = value;
}
}
This doesn't work either.
Can anyone suggest how I can make this work?
Or is my understanding of converters off base?
Should I just use a fixed format for phone numbers and force the user to enter them in that format?
I appreciate your assistance.

