开发者

Struts Validation with multiple validation rules for a single field

This 开发者_如何学Cmight be a basic question: I'm trying to understand how the Struts validation code below works:

<field property="myField" depends="validwhen, maxlength">
    <msg name="validwhen" key="error1.key" />
    <msg name="maxlength" key="error2.key"/>
    <var>
        <var-name>test</var-name>
        <var-value> isFieldsShown == "no" </var-value>
    </var>
    <var>
        <var-name>maxlength</var-name>
        <var-value>128</var-value>
    </var>
</field>

Is it like, first the validwhen rule checked and if it succeeds then the maxlength rule is checked? OR, if the validwhen returns true, then the field is considered valid without going to the maxlength rule at all?


It has been a while since I worked with the validator framework but from what I remember it goes something like the following.

When you validate a field, that field is considered valid if all of the validations pass. If at least one validation fails then the field is considered invalid.

It should make sense that if there is a list of validators to run, the validation process should exit at the first fail (no sense in running extra costly validations if the field was marked invalid because a validation already failed).

The documentation seems to indicate what I remember:

validator.dtd - field.depends attribute: The comma-delimited list of validators to apply against this field. For the field to succeed, all the validators must succeed.

Field.validate: Run all validations in the depends clause over each item in turn, returning when the first one fails.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜