Erik Hatcher on XDoclet and the Struts Validator.
It's a nice coincidence that the very week that I have to dig into the Struts Validator, two articles appear by Erik Hatcher on XDoclet and Struts. After reading these articles and browsing Matt Raible's AppFuse project code, I was able to fit the pieces together and get XDoclet to generate the right struts-config.xml
and validation.xml
entries for my form beans. Below are links to Erik's articles and some other resources I found useful in investigating Struts Validation:
- Erik Hatcher: Form Validation and Action Mapping
- Erik Hatcher: Exploit XDoclet's Struts Capabilities
- Matt Raible: AppFuse project
- <a href= "http://www.raibledesigns.com/page/rd/20030226#struts_validator_validating_two_fields"> Matt Raible: How To Add a TwoFields Validator
- Struts website: Struts Validator Guide
- Chuck Cavaness's Using the Validator Framework with Struts
Seems like everytime I try to use XDoclet, I have to tweak one of the XDoclet template files to work around a bug. This time was no exception. I found that XDoclet would only generate the right entries in struts-config.xml
if my form beans extend ActionForm, but to use the Struts Validator, I need my form beans to extend ValidatorForm. The only way I found to get around this problem was to copy struts_config_xml.xdt
out of the XDoclet xdoclet-apache-module-1.2b4.jar
file and to change the first forAllClasses
like so (my change in bold):
<!-- ========== Form Bean Definitions ============== --> <form-beans>
<XDtClass:forAllClasses type="org.apache.struts.validator.ValidatorForm"> <XDtClass:forAllClassTags tagName="struts:form" superclasses="false"> <form-bean name="<XDtClass:classTagValue tagName="struts:form" paramName="name"/>" type="<XDtClass:fullClassName/>" /> </XDtClass:forAllClassTags> </XDtClass:forAllClasses>
I believe there needs to be one of those forAllClassses
loops for each type of form: ActionForm
, ValidatorForm
, and ValidatorActionForm
. This does not appear in the current XDoclet CVS for <a href=
"http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/xdoclet/xdoclet/modules/apache/src/xdoclet/modules/apache/struts/resources/struts_config_xml.xdt?rev=1.11&content-type=text/vnd.viewcvs-markup">
struts_config_xml.xdt
. My chance to get a patch in?
Posted by Erik Hatcher on August 01, 2003 at 07:38 PM EDT #
Posted by Dave Johnson on August 01, 2003 at 08:15 PM EDT #
Posted by Joshua Davis on January 11, 2004 at 03:11 PM EST #
Posted by Tim Chen on February 05, 2004 at 03:58 AM EST #