Search code examples
struts2validationwebwork

Data Validation: Inheritance and lists


I am used WebWork and I am not able to validate my data properly.

The main two things I don't know how to do are:

-Validate a field with the validator of its super class.

Example: Say we have class Person and Class Employee. I want to validate an attribute of class Employee with my Person-validation.xml. Is it possible?

-Validate the length of a list:

I have an attribute that is a list, how could I check the length of the list and afterwards check every item within the list with its appropriate validator?

I tried:

<field name="list">
    <field-validator type="visitor">
        <message />
    </field-validator>
<field-validator type="fieldexpression">
    <param name="expression">
            list.size() < 2
        </param>
        <message key="too much items"/>
    </field-validator>
</field>

but it is now working.

Thanks


Solution

  • For you "-Validate the length of a list" problem:

    <field-validator type="fieldexpression">
       <param name="expression"><![CDATA[2 > list.size]]></param>
       <message key="too much items"/>
    </field-validator>