You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Kevin Kokal <kk...@integral7.com> on 2004/04/08 18:56:49 UTC
[validator] Validating nested beans?
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
Re: [validator] Validating nested beans?
Posted by David Graham <gr...@yahoo.com>.
The nested attribute is an interesting idea. Changes were recently
checked in that added an extends attribute but I haven't had a chance to
look at how they might be related (if at all).
Anything we can do to simplify validation configuration is a good thing.
Feel free to open a bugzilla enhancement ticket for this topic.
David
--- Kevin Kokal <kk...@integral7.com> wrote:
> 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
>
__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway
http://promotions.yahoo.com/design_giveaway/
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org