validateFloatRange Incorrect Behaviour - Using Struts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PaulCarmo
    New Member
    • Aug 2007
    • 3

    validateFloatRange Incorrect Behaviour - Using Struts

    Hello,

    I'm validating a form containing various types of data. One of the fields to be validated is an amount which must be between 0.01 and 999999.99.

    The code for this field validation in the validation.xml is;

    Code:
    <field property="amount" depends="required,webxvalidator,floatRange">
        <arg0 key="label.authorization.txn.amount"/>
        <arg1 name="floatRange" key="${var:min}" resource="false"/>
        <arg2 name="floatRange" key="${var:max}" resource="false"/>
        <var><var-name>min</var-name><var-value>0.01</var-value></var>
        <var><var-name>max</var-name><var-value>999999.99</var-value></var>
        <var>
            <var-name>dataType</var-name>
            <var-value>amount</var-value>
        </var>
    </field>
    And within the validator-rules.xml;

    Code:
          <validator name="floatRange"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateFloatRange"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionMessages,
                           javax.servlet.http.HttpServletRequest"
                  depends="float"
                      msg="errors.range"/>
    This normally works fine, and any number outside the range will flag and display the label.authoriza tion.txn.amount from MessageResource s.properties.

    But, a small range of numbers, which in this case is 1,000,000.00 to 1,000,000.03 will not flag up as being outside the range! This causes problems later as the value is accepted and is being used will being outside predefined ranges elsewere.

    The same thing happens across the board if I lower the max variable to any value. The max+.01 to max+.04 will always be (incorrectly) accepted as within the range.

    Has anyone seen this before? See anything blatent I'm doing wrong?

    Any ideas would be grand.

    Thank you,

    Paul
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    This is the Java Forum, not the JavaScript Forum. By the way, you didn't state, why you are posting the code (e.g. "need help with...").

    Comment

    • PaulCarmo
      New Member
      • Aug 2007
      • 3

      #3
      Whoops sorry, my mistake.

      I'll re-post it in the correct place.

      Cheers,

      Paul

      Comment

      Working...