WebWork2与SpringFramework集成之实例篇(原创)—数据验证的修正

类别:Java 点击:0 评论:0 推荐:

前面讲述的数据有效性验证有不妥的地方,现在做下面的修正:

PriceIncreaseFormAction-validation.xml修正如下:

<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.dtd">

<validators>

    <field name="priceIncrease.percentage">

        <field-validator type="required" short-circuit="true">

            <message key="error.not-specified">Value required.</message>

        </field-validator>

<!--

        <field-validator type="fieldexpression" short-circuit="true">

            <param name="expression">priceIncrease.percentage > 0</param>

            <message key="error.too-low">Value too low.</message>

        </field-validator>

-->

        <field-validator type="int" short-circuit="true">

            <param name="min">1</param>

            <message key="error.too-low">Value too low.</message>

        </field-validator>

        <field-validator type="int" short-circuit="true">

            <param name="max">50</param>

            <message key="error.too-high">Value too high.</message>

        </field-validator>

    </field>

</validators>

ActionSupport.properties修正如下:

#error.too-low=You have to specify a percentage higher than ${expression}%!

error.too-low=You have to specify a percentage higher than ${min-1}%!

本文地址:http://com.8s8s.com/it/it15784.htm