You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by jelything <ja...@shaw.ca> on 2005/03/18 19:40:30 UTC
Validating Nested DynaValidator Forms
I have a DynaValidatorForm that holds many items, including an
ArrayList of DynaValidatorForms. Calling validate() on the main form
works just fine, but how do I get the nested forms to validate?
If I iterate through the ArrayList, and cast them back to a
DynaValidatorForm and then simply call validate on them, I get:
java.lang.NullPointerException at
org.apache.struts.validator.DynaValidatorForm.validate(DynaValidatorForm.java:144)
Any ideas?
J
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validating Nested DynaValidator Forms
Posted by Rick Reumann <st...@reumann.net>.
jelything wrote the following on 3/18/2005 4:58 PM:
> Thanks for the feedback.
>
> Why wouldn't I want to nest forms?
Because how are you going to populate them and create them all? For
example, imagine the case where you needed to a master detail edit of
company employees (granted this might not be a practical example, but
using this to explain the point)).
The hierachy might look like...
Company Object
Store objects
Division Objects
Emloyee Objects
So before doing your mass edit for display, your backend might be giving
you a "Company" object which iniside has Stores and inside stores is a
collection of Divisions (accounting, sales) and then in each division is
a list of Employee objects.
For this example we then want to edit the employees. So in your scenario
you'll have to create form beans for Company, Store, divions, employe
and then somehow get them all created and nested within each other. Why
do this when you can just have one form bean with "Company" as the
property? Then you just nest iterate over the company, stores,
devisions, employees, and you can thus edit the employees and hit submit
and presto your Company business object is all nice and populated.
Explain to me how you would do the above while nesting form beans?
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validating Nested DynaValidator Forms
Posted by jelything <ja...@shaw.ca>.
Thanks for the feedback.
Why wouldn't I want to nest forms? Its entirely possible I missed the
point, but I thought that was what <nested:xxx> was for? Everything
but the validating works just fine.
I'm sure that I could write my own validation method, but I'm trying
to KISS and use the nice validation.xml route
J
--- In struts@yahoogroups.com, Rick Reumann <st...@r...> wrote:
> Ok couple of things...
>
> 1) I would NOT nest forms. I think that's just asking for trouble. I
> would simply use ONE form and have your collection a s property in that
> form. (The of course your collection can hold objects which have
> collections..etc etc). But just nest a collection of beans, or even one
> bean with the collections inside.
>
> 2) I'm not sure how declarative validation works over nested objects
> (using validation rules). I know when I have a lot of nested objects
> (which I do quite often), I find it easiest to just create my own
> validation (Recurse over the nested objects and perform the checks).
>
> --
> Rick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@s...
> For additional commands, e-mail: user-help@s...
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Validating Nested DynaValidator Forms
Posted by Rick Reumann <st...@reumann.net>.
jelything wrote the following on 3/18/2005 1:40 PM:
> I have a DynaValidatorForm that holds many items, including an
> ArrayList of DynaValidatorForms. Calling validate() on the main form
> works just fine, but how do I get the nested forms to validate?
>
> If I iterate through the ArrayList, and cast them back to a
> DynaValidatorForm and then simply call validate on them, I get:
>
> java.lang.NullPointerException at
> org.apache.struts.validator.DynaValidatorForm.validate(DynaValidatorForm.java:144)
>
> Any ideas?
Ok couple of things...
1) I would NOT nest forms. I think that's just asking for trouble. I
would simply use ONE form and have your collection a s property in that
form. (The of course your collection can hold objects which have
collections..etc etc). But just nest a collection of beans, or even one
bean with the collections inside.
2) I'm not sure how declarative validation works over nested objects
(using validation rules). I know when I have a lot of nested objects
(which I do quite often), I find it easiest to just create my own
validation (Recurse over the nested objects and perform the checks).
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org