Hi Samuel,

Apparently, you're right : @ValidateNestedProperties references @Validate,
not @ValidateNestedProperties again...

If this can help you, I have a "workaround". I'm using a custom
NestedValidationMetadataProvider in Woko, that allows you to write
validation annotations inside your POJOs, and have Stripes use them. Stuff
like this :

class MyAction implements ActionBean {
  ...
  @ValidateNestedProperties([])
  MyClass myProp
  ...
}

and

class MyClass {
  @Validate(required=true)
  String foo
}

The basic idea is that when an action bean property's marked with an empty
@ValidateNestedProperties, the NestedMetadataValidationProvider recurses
into the property and applies it's validation info.
With the example above, request parameter 'myProp.foo' has to be provided.

Of course, the provider can recurse to any depth, which means you can even
write this :

class MyClass {
  @ValidateNestedProperties([])
  MyOtherClass other
}

class MyOtherClass {
  @Validate(...)
  String bar
}

Last, the metadata provider will favor the run-time type of the property.
You can even write this :

class MyAction implements ActionBean {
  ...
  @ValidateNestedProperties([])
  Object prop
}

Then the validation metadata provider will (if prop ain't null of course)
get the runtime type of the instance referenced by 'prop' and introspect for
validation errors.

I tend to think this behavior should be standard in Stripes. Yeah, I know,
you shouldn't have dependencies of your Domain Model on Stripes, it's
baaaad...
But I often have "collaborators" to my actions that are not part of the
domain model. They're UI objects. And I don't always know the runtime type
of the action's properties (hey, inheritance...).
So I'd like to annotate whatever class I want with @Validate, and if it's
reachable by the action bean at request processing time, then have Stripes
validate everything. Feels natural, doesn't it ?

Last, this "nested validation metadata provider" allows for better
factorization the validation logic : you can delegate to action
collaborators, and the validation rules will depend on the objects
referenced by your action bean.

Anyway, in case you're interested :
https://github.com/vankeisb/woko2/blob/master/stripes-plugins/src/main/java/woko/actions/nestedvalidation/NestedValidationMetadataProvider.java

I'd be happy to have the community feedback on this btw...

HTH

Cheers

Remi

2011/3/10 samuel baudouin <osenseij...@gmail.com>

> Hi all!
>
> I was wondering : is it possible to do nested validation to more than one
> level?
>
> Lets say I want to validate the name of an Account contained in a WebModel,
> for instance : getWebModel().getAccount().getName()
>
> I know the annotation @ValidateNestedProperties makes it possible to
> validate one level , but apparently it is impossible to go deeper...
>
> I think i ll fall back to validation methods but that would have been nice,
> no?
>
> Any idea?
>
> Cheers
> --
> Samuel Baudouin
>
>
> ------------------------------------------------------------------------------
> Colocation vs. Managed Hosting
> A question and answer guide to determining the best fit
> for your organization - today and in the future.
> http://p.sf.net/sfu/internap-sfd2d
> _______________________________________________
> Stripes-users mailing list
> Stripes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to