|
From: Thomas V. de V. <tho...@ac...> - 2005-09-12 20:07:04
|
That would be excellent stuff Steven!
I have used this on a very large scale and combined it with a JSP tag that=
=20
reads the annotation and writes appropriate JavaScript. On the server side,=
=20
the annotation can be read to execute server-side validation logic.
With your solution I'd be worried about typos in the validation rules.=20
Wouldn't it be better to have something more explicit licate=20
@ValidateRequired, @ValidateEmail, and @ValidateDate, ....
To respond to Sean's question, you could have a @ValidateRequiredIfBlank("
mybean.afield") but there are limits to this of course.=20
I guess you'd also have to pass another parameter that points to the key of=
=20
a message that you want to show for validation messages.
Thomas
On 9/12/05, Steven Devijver <ste...@in...> wrote:
>=20
> I've had a couple of requests now to include support for annotations.
> Basically we could do something like this:
>=20
>=20
> public @interface Validate {
> String constraint();
> String code();
> String message();
> String[] arguments();
> }
>=20
> So you could do:
>=20
> package test;
>=20
> public class MyClass {
>=20
> private String firstName =3D null;
> @Validate(
> constraint =3D "? not blank",
> code =3D "firstName_blank"
> )
> public String getFirstName() { return this.firstName; }
> public void setFirstName(String firstName) { this.firstName =3D
> firstName; }
>=20
> private String lastName =3D null;
> @Validate("? not blank") // would use code:
> test.MyClass_lastName_invalid
> public String getLastName() { return this.lastName; }
> public void setLastName(String lastName) { this.lastName =3D
> lastName; }
> }
>=20
> Any thoughts on this?
>=20
> Steven Devijver
> Senior consultant
> @ Interface21
> ste...@in...
>=20
>=20
>=20
> On 12 Sep 2005, at 14:51, Sean Miller wrote:
>=20
>=20
>=20
>=20
> > This looks like a really neat option for single-field validations;
> > is there an obvious way of handling multi-field validations as
> > annotations, like
> >
> > collision : (firstName is not blank or lastName is not blank) and
> > userid is not blank : 'Fill in either name or id'
> >
> > Cheers,
> > Sean Miller.
> >
> > Thomas Van de Velde wrote:
> >
> >
> >
> >
> >
> >> I am wondering if it'd make sense to have the validation rules
> >> defined as annotations.
> >> e.g.
> >>
> >> @RequiredField
> >> @EmailAddress
> >>
> >> I've worked with forms that contains 2 000 + fields and
> >> maintaining external XML files is really cumbersome in such a
> >> case? Any thoughts, pros/cons?
> >>
> >>
> >>
> >>
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net email is Sponsored by the Better Software Conference & EXPO
> > September 19-22, 2005 * San Francisco, CA * Development Lifecycle
> > Practices
> > Agile & Plan-Driven Development * Managing Projects & Teams *
> > Testing & QA
> > Security * Process Improvement & Measurement * http://www.sqe.com/
> > bsce5sf
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >
> >
> >
> >
> >
>=20
>=20
>=20
>=20
>=20
>=20
> -------------------------------------------------------
> SF.Net email is Sponsored by the Better Software Conference & EXPO
> September 19-22, 2005 * San Francisco, CA * Development Lifecycle=20
> Practices
> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & Q=
A
> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
|