Hi all,
I've posted on this topic
http://old.nabble.com/reusing-validation-annotations-tp18954793p18957454.html
before
and it generated a bit of interesting discussion. I won't rehash it but to
summarize in one line, my
only gripe about Stripes for a long time is that I find myself constantly
having to repeat code
for front end constructs - either validation or java bean properties that
are
shared in a lot of places. I recently had a case that pushed me over the
edge with this, so I
scratched my itch and made a new annotation: ImportProperties.
ImportProperties works analogously to a Java import - you can apply it to a
field and Stripes
then "imports" all the properties from that field into the "namespace" of
the action bean.
These then behave for the purposes of binding and validation exactly as if
they were declared at the top level on that
action bean. The import also brings with it any validations that are
declared
on the child bean, and these can be nested recursively. Some examples (in
Groovy for brevity):
class PersonActionBean implements ActionBean {
@ImportProperties
Person person;
}
class Person {
@Validate(required=true,minvalue=0)
int age;
@ImportProperties
Name name;
}
class Name {
@Validate(required=true,maxlength=60)
String firstName;
@Validate(required=false,maxlength=60)
String middleName;
@Validate(required=true,maxlength=60)
String lastName;
}
So the key here is that there is one ActionBean that is importing properties
from a bean (Person) which in turn is importing properties from another bean
(Name). The imports allow all the parameters to be bound at the top level
using their names without any prefixes to navigate the bean path. So a
query string such as this will work:
?age=30&firstName=John&lastName=Smith
The validations are imported too, so the following will fail (because
lastName is required):
?age=30&firstName=John
I've http://www.badboy.com.au/stripes/import.html posted
more details including a patch and pre-built jar file based on the Stripes
trunk
in case anybody wants to try it out. If it's useful I'd be happy to
help get it into the Stripes core. On the other hand, based on past
discussions
I understand that Stripes might move in a different direction in the future
so
this might not be appropriate. Still, I figure there might be someone out
there
who finds it useful in the meantime, and I'd love to hear any feedback /
thoughts
about it if anybody tries it out.
Cheers,
Simon
--
View this message in context:
http://old.nabble.com/An-experimental-new-Stripes-Annotation%3A--ImportProperties-tp27844393p27844393.html
Sent from the stripes-users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users