Hi,
I've been developing a JSP taglib that will reflect on a JSR311
annotated method and automatically generate an HTML form to represent
that method. This is useful during application development because the
front end automatically tracks changes made to the REST interface.
In addition, the JSP can generate client side JavaScript for parameter
validation that matches the parameter validation on the method. For
example, if the parameter is an int then the form input box for that
parameter will only accept numbers. It will also populate the form
input box with the value of any @DefaultValue annotations attached to
the parameter.
Currently, the development is only a proof of concept but it does work
(for methods with only String and int parameters). My next task is to
look at being able to return the form to the user when server side
parameter validation fails, with the form populated by the values that
the user submitted. I also want to extend the paramater types to all
Java primitives and equivalent objects, and enums. There's some message
lookup and translation work too.
I am happy to submit the proof of concept to the community, and am
likely to develop it further, and also to suggest some improvements
that will benefit this kind of dynamic processing.
1) When the server side validation of parameters fails, Jersey should
validate all parameters - the returned form should explain all
incorrect parameters, not the first encountered incorrect parameter.
2) JERSEY-351 and JERSEY-399: Jersey should support parameter
validation via additional annotations. The JSP that builds client side
forms can apply similar validation at the client. This will reduce the
number of incorrect requests that a user can make to the server. The
ideal would be if all parameter validation could be performed through
the annotation mechanism, via a set of validation classes specified in
the annotations. The JSP taglib can do a lookup against each known
validator class for a JavaScript equivalent. Unknown validators are
ignored client side. For Example: @Validation({ @Validator(value =
LessThan.class, initparams = "100"), @Validator(value =
GreaterThan.class, initparams = "0"), @Validator(value = Custom.class)
}) would generate JavaScript for the known LessThan and GreaterThan
validators, but not the custom validator.
Is the JSP taglib described above of interest to the Jersey dev team?
Chris