« Custom systems devel... | Main | Roller 0.9.7.5 progr... »

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:

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?

Comments:

You don't need to change the template. ActionForm is the superclass to ValidatorForm and XDoclet handles that fine. But... the trick is to be sure the JAR with the validator classes is in the XDoclet task (webdoclet in this case) classpath. Add that and use the default template and you should be fine.

Posted by Erik Hatcher on August 01, 2003 at 07:38 PM EDT #

Excellent! I tried your suggested fix and it worked. Thanks Erik.

Posted by Dave Johnson on August 01, 2003 at 08:15 PM EDT #

Eric, Thanks for posting this solution! I had exactly the same problem (mysteriously dissapearing form-bean declarations), and adding the main struts jar to XDoclet's classpath solved the problem.

Posted by Joshua Davis on January 11, 2004 at 03:11 PM EST #

XDoclet 1.2's support of Struts is buggy at best. While I use it an love it for what it CAN do. I don't try to even hope that it can do more. Look at the struts.action-forward/struts.action-exception bug for example. "Seems like everytime I try to use XDoclet, I have to tweak one of the XDoclet template files to work around a bug." Very accurate statement but some bugs (like the above) require more of a rewrite then a tweak. Here's to hoping that XDoclet 2 will answer all our XDoclet needs. :-/

Posted by Tim Chen on February 05, 2004 at 03:58 AM EST #

Post a Comment:
  • HTML Syntax: NOT allowed

« Custom systems devel... | Main | Roller 0.9.7.5 progr... »

Welcome

This is just one entry in the weblog Blogging Roller. You may want to visit the main page of the weblog

Related entries

Below are the most recent entries in the category Java, some may be related to this entry.