Hi Mike,
Thanks for the reply !
I must have missed something. The 2 methods I see in
ValidationMetadataProvider are :
Map<String, ValidationMetadata> getValidationMetadata(Class<?> beanType);
ValidationMetadata getValidationMetadata(Class<?> beanType,
ParameterName property);
As you see, the *instance* of the bean is never passed to any of thome
methods, so it's basically only "class-based" as far as I understand
it : "gimme the validation metadata for this bean class".
What I'd need is really to get the validation metadata from the bean
instance, not from it's static class definition...
Say I have an action bean like :
@UrlBinding("/generic.action")
class MyGenericActionBean implements ActionBean {
private Object object; // non typed, Stripes can't guess about it by
.bean class introspection
@DefaultHandler
public Resolution doIt() { ... }
}
And I want validation to work if a request like this is submitted :
http://.../myapp/generic.action?object.prop=notanumber
... and of course actionBean.object references a MyPojo like this :
class MyPojo {
@Validate(required=true)
private String prop; // + get/set
}
As you see, the validation is depending on the run-time type of the
'actionBean.object' property...
Using ValidationMetadataProvider as is, I can't see a way of doing it :(
I've currently written a quite ugly subclass of
DefaultActionBeanPropertyBinder, but really, it sucks...
Cheers
Rémi
2009/3/1 Mike McNally <[email protected]>:
> I've implemented a subclass on the DefaultValidationMetadataProvider
> that does exactly what you suggest. (One of the nice things you can do
> is pick up implicit validation rules for some things from JPA
> annotations.) It's not too hard really - just look at the code that
> does the "ValidateNestedProperties", and it'll be something like that.
>
> One of the things you may end up doing, as I did, is putting together
> some code to handle multiple layers of validation metadata. For
> example, you may want to let the action beans handle the stipulation
> of what properties are "required" - consider the difference between a
> "create" and an "edit" operation. To do that, you're variant of the
> metadata provider will have to perform the ValidateNestedProperties
> work like the current code does, and then proceed to look down into
> the property type to look for more validation information. When it
> finds it, it will want to merge that onto what's been found already.
>
> On Sun, Mar 1, 2009 at 9:37 AM, VANKEISBELCK Remi <[email protected]> wrote:
>> Hi folks,
>>
>> I'd like to use the Stripes validation annotations in POJOs that are
>> used as ActionBean properties :
>>
>> // not an action bean
>> class MyPojo {
>> �...@validate(required=true)
>> private String myProp; // + usual get/set
>> }
>>
>> class MyActionBean implements ActionBean {
>> private MyPojo myPojo; // + get/set, but without @ValidateNestedProperties
>> }
>>
>> Of course, I don't want to change anything in the action itself (using
>> ValidateNestedProperties).
>>
>> The idea is simple : I'd like Stripes to recurse on the nested
>> properties, and check for Validation Annotations there, not only on
>> the bean itself...
>>
>> I'm currrently looking at how DefaultActionBeanPropertyBinder and
>> DefaultValidationMetadataProvider, but it seems (after a quick look)
>> that it's not possible to hook some "instance-specific" code that
>> would do the job of recursing on "myProp", and add the nested object's
>> class Validation Annotations to the top level's bean class... I'm
>> currently trying to hack DefaultPropertyBinder, but it seems to
>> require quite a lot of stuff to be overriden (and almost entirely
>> rewritten)...
>>
>> Any idea ?
>>
>> Cheers
>>
>> Remi
>>
>> ------------------------------------------------------------------------------
>> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
>> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
>> -Strategies to boost innovation and cut costs with open source participation
>> -Receive a $600 discount off the registration fee with the source code: SFAD
>> http://p.sf.net/sfu/XcvMzF8H
>> _______________________________________________
>> Stripes-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/stripes-users
>>
>
>
>
> --
> Turtle, turtle, on the ground,
> Pink and shiny, turn around.
>
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development