Issue Details (XML | Word | Printable)

Key: STR-2321
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Paul Benedict
Reporter: Nate Minshew
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Struts 1

Validator validwhen comparisons of doubles

Created: 29/Dec/04 09:37 PM   Updated: 26/Aug/07 11:44 PM
Return to search
Component/s: Core
Affects Version/s: 1.2.2, Nightly Build
Fix Version/s: 1.4.0

File Attachments:
  Size
Java Source File ValidWhenParser.java 2004-12-29 09:46 PM Nate Minshew 15 kB
Environment:
Operating System: Windows XP
Platform: PC
Issue Links:
Duplicate
 
Reference
 

Bugzilla Id: 32875


 Description  « Hide
I ran into a problem this week where validwhen wasn't working correctly when
trying to compare 2 doubles. I have 2 fields, one a minimum value and the other
a maximum value. I setup in the validation.xml this validator dependency:

<field property="sizeHeightMin" depends="required, double" >
    <arg0 key="displayName.sizeHeightMin" />
    <msg name="double" key="errors.numeric" />
</field>
<field property="sizeHeightMax" depends="required, double, validwhen" >
    <arg0 key="displayName.sizeHeightMax" />
    <arg1 key="displayName.sizeHeightMin" />
    <msg name="double" key="errors.numeric" />
    <msg name="validwhen" key="errors.range" />
    <var>
        <var-name>test</var-name>
        <var-value>(*this* > sizeHeightMin)</var-value>
    </var>
</field>

But when I would enter 6.5 for the min and 11.5 for the max it would fail
validation saying that the max was less than the min. After debugging and
tracking down the problem I discovered that the evaluateComparison(Object,
Object, Object) method in ValidWhenParser.class was only checking to see if the
values were integers and if not doing a string comparison, thus the reason I was
getting the validation failure. Also in that method it does a check to see if
the objects passed in are of type Integer.class. Unless I'm missing something I
don't believe that will ever happen since in ValidWhen.class and in the field
method of ValidWhenParser.class you retrieve the value with
ValidatorUtils.getValueAsString(bean, property), thus the value will always be a
string. I have added a patch for this issue and will be sending it in.

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order