Albeit crude, I think that declaring it as a String is the right thing to
do. The value is sent across the wire as a string and Struts attempts to
convert it to the proper data type using introspection. The advantage of
declaring it as a String is that you have more granular control over
validation as you have already mentioned. Once your form has properly
validated the field, then you can safely use Integer.parseInt() in the
Action class to convert it to the expected primitive value.

My forms are usually contain all String fields. I then use an exportObject()
which returns a value object with the data in the appropriate
native format (ints, floats, Date, etc...) I can then pass the value object
to a business delegate to perform any business logic processing.
I also have an importObject() which maps and converts the value object data
members into the appropriate String fields.

That's just my preference.

robert

> -----Original Message-----
> From: cool dude [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, February 09, 2002 7:30 AM
> To: [EMAIL PROTECTED]
> Subject: Form Bean Validation problem
>
>
> Hi,
>    Here's a small problem that I'm facing. I have a
> form which has an integer field, say a cost of some
> item. Now, I need to do the validation for this
> form-field to make sure that the user does not enter a
> non-numeric data in this field. I have the form
> containing this field as a primitive int. The problem
> is that whenever a non-numberic value is entered the
> value is reset to zero. This leads to two problems,
> one it doesn't give me a chance to find out that the
> user has entered a non-numeric value in my validate
> method & secondly, I end up losing the value that the
> user had entered & hence can't show him the value
> back. The rather crude solution to this is to make the
> numeric form-field value a String & do the check in
> the validate() to find if a non-numeric value is
> entered. But I'm not happy with this solution as it
> requires me to decalre a field as string even when it
> should have been an int or float ...
>
> Is there any other way around this prob?
>
> Thanx in advance,
> VD.
>
> __________________________________________________
> Do You Yahoo!?
> Send FREE Valentine eCards with Yahoo! Greetings!
> http://greetings.yahoo.com
>
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to