commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Kokal <kko...@integral7.com>
Subject [validator] Validating nested beans?
Date Thu, 08 Apr 2004 16:56:49 GMT
I'm using commons-validator to validate beans (not forms). In reading 
the "TODO" list for the project,
it sounds like this is the direction the project is heading. One 
consideration, though, is that beans
tend to have other beans nested within themselves, whereas forms just 
have fields. Has anyone had
any success getting nested validations to work? A simple scenario may 
illustrate my point:

Classes A, B, and C are all beans. Classes A and B both contain C, and 
both have getC() methods.
I want to set up validation rules for class C, and I want those 
validations run whenever I validate A and B,
too.

One solution is to use the dot-notation in the property name:

<form name="A">
    <field property="c.x"  depends="required"/>
    <field property="c.y"  depends="required"/>
    <...other "A" validations...>
</form>

<form name="B">
    <field property="c.x"  depends="required"/>
    <field property="c.y"  depends="required"/>
    <...other "B" validations...>
</form>

But this doesn't nicely lend itself to code reuse, because I have to 
repeat my "C" validations
everywhere. I'm thinking that something like this may be better:

<form name="A">
    <field property="c"  nested="C"/>
    <...other "A" validations...>
</form>

<form name="B">
    <field property="c"  nested="C"/>
    <...other "B" validations...>
</form>

<form name="C">
    <field property="x"  depends="required"/>
    <field property="y"  depends="required"/>
</form>

This is obviously a longer-term solution, requiring changes to the 
commons-validator core. Has anyone
instead tried doing something similar using a validator method?



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


Mime
View raw message