By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,573 Members | 3,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,573 IT Pros & Developers. It's quick & easy.

validateFloatRange Incorrect Behaviour - Using Struts

P: 3
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;

Expand|Select|Wrap|Line Numbers
  1. <field property="amount" depends="required,webxvalidator,floatRange">
  2.     <arg0 key="label.authorization.txn.amount"/>
  3.     <arg1 name="floatRange" key="${var:min}" resource="false"/>
  4.     <arg2 name="floatRange" key="${var:max}" resource="false"/>
  5.     <var><var-name>min</var-name><var-value>0.01</var-value></var>
  6.     <var><var-name>max</var-name><var-value>999999.99</var-value></var>
  7.     <var>
  8.         <var-name>dataType</var-name>
  9.         <var-value>amount</var-value>
  10.     </var>
  11. </field>
  12.  
And within the validator-rules.xml;

Expand|Select|Wrap|Line Numbers
  1.       <validator name="floatRange"
  2.             classname="org.apache.struts.validator.FieldChecks"
  3.                method="validateFloatRange"
  4.          methodParams="java.lang.Object,
  5.                        org.apache.commons.validator.ValidatorAction,
  6.                        org.apache.commons.validator.Field,
  7.                        org.apache.struts.action.ActionMessages,
  8.                        javax.servlet.http.HttpServletRequest"
  9.               depends="float"
  10.                   msg="errors.range"/>
  11.  
This normally works fine, and any number outside the range will flag and display the label.authorization.txn.amount from MessageResources.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
Aug 29 '07 #1
Share this Question
Share on Google+
2 Replies


Nepomuk
Expert 2.5K+
P: 3,112
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...").
Aug 29 '07 #2

P: 3
Whoops sorry, my mistake.

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

Cheers,

Paul
Aug 29 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.