[ 
https://issues.apache.org/struts/browse/STR-2321?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_39959
 ] 

Henri Yandell commented on STR-2321:
------------------------------------

Makes sense. The ValidWhenParser defines a DECIMAL_LITERAL to be:

DECIMAL_LITERAL : ('-')? ('1'..'9') ('0'..'9')*;

Which doesn't support decimals (despite the name). Making it support decimals 
appears to be trickier than just adding the pattern for a decimal format - you 
have to split DECIMAL_LITERAL and INTEGER_LITERAL so the right types of objects 
are made, and then you need to find a way to stop the DECIMAL, INTEGER clashing 
with the INTEGER_LITERAL, OCTAL_LITERAL and IDENTIFIER. Way beyond my Antlr 
knowledge at the moment, but it does explain why the examples I looked at get 
complex in this area.

> [validator] Unable to do validwhen comparisons of doubles.
> ----------------------------------------------------------
>
>                 Key: STR-2321
>                 URL: https://issues.apache.org/struts/browse/STR-2321
>             Project: Struts 1
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: Nightly Build
>         Environment: Operating System: Windows XP
> Platform: PC
>            Reporter: Nate Minshew
>         Assigned To: Struts Developers
>            Priority: Minor
>         Attachments: ValidWhenParser.java
>
>
> 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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to