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
  • phvfl
    Recognized Expert New Member
    • Aug 2007
    • 173

    #2
    Hi Paul,

    Is this not being validated using Java (as opposed to Javascript) as there seem to be reference to a Java namespace in the XML.

    If this is Java then you would be better moving this question to the Java Forum

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Originally posted by phvfl
      Hi Paul,

      Is this not being validated using Java (as opposed to Javascript) as there seem to be reference to a Java namespace in the XML.

      If this is Java then you would be better moving this question to the Java Forum
      Moved to the Java forum.

      Comment

      • Nepomuk
        Recognized Expert Specialist
        • Aug 2007
        • 3111

        #4
        Originally posted by acoder
        Moved to the Java forum.
        This question allready exists here and was posted in the JavaScript forum due to my mistake. Sorry for that.

        Comment

        Working...