PDA

View Full Version : Using Convert in validation definitions



LaTtEX
03-10-2006, 03:16 AM
Aleks,

This is somewhat related to the topic I've previously posted (http://forum.springframework.net/viewtopic.php?t=384). To go around the databinding quirks of Spring, I used a dummy "middle" class to accept the fields I'm expecting as strings, and then regex validate these fields to ensure that the proper types are keyed in.

My problem now is comparing these fields when they are related:

For example, I have a form that searches for a certain range of a particular numeric field; I have one textbox that serves as an input for a "from" field to denote the lowerbound of the search, and another "to" field to denote the upperbound of the search.

My problem comes in when I use a condition validator to determine whether the "to" textbox is greater than the "from" textbox. While the comparisons work when you have the same number of digits in the number (e.g., "99.9" evaluates as greater than "88.8"), the problem comes when you have differences in the number of digits (e.g., "9.99" is still greater than "88.8" when it should evaluate as lesser).

I've tried solving this by putting a Convert.ToDouble() on the corresponding validator test, but the page throws an error once it reaches that test.

I feel like the only way to solve this problem would be to assign the proper datatypes to the datamodel in question, but that brings me back to square 1: an error is thrown during data unbinding if non-numeric values are put in the textboxes.

So now I'm running in circles :(

Hope the new databinding model comes out soon enough, but in the meantime, any ideas on how to work around this one? Can I use some conversion function within the tests so that they would validate as numbers, not as strings?

Thanks,

-Jon

Aleks Seovic
03-10-2006, 09:53 AM
Yes, you definitely want to have proper data types in the model -- anything else is an ugly hack that you really shouldn't have to live with.

I actually have most of the data binding done, including this functionality. I only need to add support for formatters and parsers and I will commit everything. Hopefully tomorrow or over the weekend.

If you cannot wait until Monday, you can use Convert.ToDouble, but you need to register a type alias for Convert class so it can be resolved by the expression eval engine.

Later,

Aleks

LaTtEX
03-11-2006, 06:53 AM
I will wait. Thanks :)