Java Reference
In-Depth Information
Browser
request
contact=5
String
"5"
TypeConverter<Contact>
Contact
setContact(Contact)
ActionBean
Figure 5.5: Using a type converter to load a contact
Here is an example with the PhoneNumber class:
package stripesbook.model;
public class PhoneNumber {
private int areaCode;
private int prefix;
private int suffix;
private static final Pattern pattern = Pattern.compile(
"\\(?(\\d{3})\\)?[-. ]?(\\d{3})[-. ]?(\\d{4})");
public PhoneNumber() {
}
public PhoneNumber( int areaCode, int prefix, int suffix) {
this .areaCode = areaCode;
this .prefix = prefix;
this .suffix = suffix;
}
// Stripes will use this for String -> PhoneNumber type conversion
public PhoneNumber(String input) {
if (input != null ) {
Matcher matcher = pattern.matcher(input);
 
 
Search WWH ::




Custom Search