You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Robin Mannering <ro...@mtndesigns.co.uk> on 2009/09/17 13:31:59 UTC

Field-Validator and BigDecimal

Hello all,

I have a rather strange validation problem.

I have a field agencyCommRate declared as a BigDecimal.

I need to validate that a value between 0.0 and 100.0 is entered and 
assumed the following validation rules would work.

Values outside the range are picked up correctly.

However, when the values are inside the range, the validation rule 
'requiredstring' insists that there is no value for agencyCommRate and 
validation always fails.

Can anybody spot a glaring mistake in my below declaration, or is there 
a known problem on combining requiredstring and double validation rules?

Thanks
Robin



    <field name="agencyCommRate">
        <field-validator type="requiredstring">
            <param name="trim">true</param>
            <message 
key="form.createShopForm.validationMsg.agencyCommRateRequired"><![CDATA[ 
error msg 1 ]]></message>
        </field-validator>            
        <field-validator type="double">
            <param name="minInclusive">0.00</param>
            <param name="maxInclusive">100.00</param>
            <message 
key="form.createShopForm.validationMsg.agencyCommRateBadValue"><![CDATA[ 
error msg 2 ]]></message>
        </field-validator>        
    </field>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Field-Validator and BigDecimal

Posted by strutstwouser <st...@gmail.com>.

Robin Mannering-4 wrote:
> 
> Values outside the range are picked up correctly.
> 
> However, when the values are inside the range, the validation rule 
> 'requiredstring' insists that there is no value for agencyCommRate and 
> validation always fails.
> 
> 
Looking at source of RequiredStringValidator, seems like the requiredstring
fails since it encounters a non-String value 

if (!(value instanceof String)) {
            addFieldError(fieldName, object);

Can you try replacing <field-validator type="requiredstring"> with
<field-validator type="required"> 

Also, you may want to put short-circuit="true" attribute so that the
subsequent validations don't fire if the previous ones fail

Btw, this does not explain how it works fine for values outside the range..


HTH
-- 
View this message in context: http://www.nabble.com/Field-Validator-and-BigDecimal-tp25489575p25530407.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org