You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Nikita Tovstoles <ni...@gmail.com> on 2010/03/12 19:03:50 UTC
TextField w/ bean as model object?
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
Re: TextField w/ bean as model object?
Posted by MattyDE <uf...@gmail.com>.
Iam in hope duke you will share your solution with us ... Want to know it too
;)
igor.vaynberg wrote:
>
> there are two ways to do this
>
> either you do everything in the converter
>
> take the string and convert it into the area, if the zip is incorrect
> throw a conversion exception
>
> or you split the two
>
> have a converter that converts the string into the area and a
> validator that makes sure the area is valid
>
> -igor
>
>
> On Fri, Mar 12, 2010 at 10:03 AM, Nikita Tovstoles
> <ni...@gmail.com> wrote:
>> 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
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
--
View this message in context: http://old.nabble.com/TextField-w--bean-as-model-object--tp27880787p27900904.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: TextField w/ bean as model object?
Posted by Igor Vaynberg <ig...@gmail.com>.
there are two ways to do this
either you do everything in the converter
take the string and convert it into the area, if the zip is incorrect
throw a conversion exception
or you split the two
have a converter that converts the string into the area and a
validator that makes sure the area is valid
-igor
On Fri, Mar 12, 2010 at 10:03 AM, Nikita Tovstoles
<ni...@gmail.com> wrote:
> 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org