|
From: Steven D. <ste...@in...> - 2005-09-12 20:56:52
|
On 12 Sep 2005, at 22:06, Thomas Van de Velde wrote:
> That would be excellent stuff Steven!
>
> I have used this on a very large scale and combined it with a JSP
> tag that reads the annotation and writes appropriate JavaScript.
> On the server side, the annotation can be read to execute server-
> side validation logic.
>
> With your solution I'd be worried about typos in the validation
> rules. Wouldn't it be better to have something more explicit
> licate @ValidateRequired, @ValidateEmail, and @ValidateDate, ....
>
We could obviously create these annotation classes as shorthand
notations but writing your own constraints is much more powerful, in
the end that's what Valang is about.
I'm not sure if there is a common set of validation annotation
classes but to me it makes sense to not couple these annotations to
Spring or Valang. With annotations all you would need to do is have a
Spring Validator implementation that reads the annotations of a class
and validates the objects that come in. These annotated classes could
then be used with Struts or WebWork or any other framework that wants
to support them.
> To respond to Sean's question, you could have a
> @ValidateRequiredIfBlank("mybean.afield") but there are limits to
> this of course.
>
> I guess you'd also have to pass another parameter that points to
> the key of a message that you want to show for validation messages.
>
> Thomas
>
> On 9/12/05, Steven Devijver <ste...@in...> wrote:
> I've had a couple of requests now to include support for annotations.
> Basically we could do something like this:
>
>
> public @interface Validate {
> String constraint();
> String code();
> String message();
> String[] arguments();
> }
>
> So you could do:
>
> package test;
>
> public class MyClass {
>
> private String firstName = null;
> @Validate(
> constraint = "? not blank",
> code = "firstName_blank"
> )
> public String getFirstName() { return this.firstName; }
> public void setFirstName(String firstName) { this.firstName =
> firstName; }
>
> private String lastName = null;
> @Validate("? not blank") // would use code:
> test.MyClass_lastName_invalid
> public String getLastName() { return this.lastName; }
> public void setLastName(String lastName) { this.lastName =
> lastName; }
> }
>
> Any thoughts on this?
>
> Steven Devijver
> Senior consultant
> @ Interface21
> ste...@in...
>
>
>
> On 12 Sep 2005, at 14:51, Sean Miller wrote:
>
>
>
>
> > 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
> >
> >
> >
> >
> >
>
>
>
>
>
>
> -------------------------------------------------------
> 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
>
|