I'd appreciate another pair of eyes on the following:

I have a US ZIP Code input text field that I'd like to bind to an Area
bean. The idea is that the component would prompt/display for a 5-digit zip
code but getModelObject() would return an Area:

class ZipInput extends RequiredTextField<Area>;

where Area is:

class Area{
int zipcode;
UsState state; //enum
String city;
}

there is also a AreaService service:

//returns true only if zipCode is a valid US zip code
boolean isValidZipCode(int zipcode);

//return Area bean for given zipCode; throws exception if 'zipCode' isn't a
valid US Zip Code
Area getArea(int zipCode);


The component needs to:

   - validate that input is present (RequiredValidator?)
   - convert input from String integer
   - at some pt call AreaService.isValidZipCode (again, a validation task)
   - call AreaService.getArea (a conversion task)


My main problem is that it seems like AreaService.getArea() should be
wrapped into a IConverter, but it, in turn, requires a validation step.
However, conversion runs before validation (ie. first I need to convert
string->int). So, I guess, I am unsure which of the above should be wrapped
into a Converter and which into a Validator (trying to maintain some
separation of responsibilities). Should I create a converter that chains
String<>Int and Int<>Area conversions? Which would execute
AreaService.getArea(zipCode)?

thanks
-nikita

Reply via email to