Generating indexed-property ready ActionForms with XDoclet
One of the issues with using XDoclet to generate your Struts ActionForms (from POJOs) is that out-of-the-box, your Forms will not support indexed properties. This means that if you have a List on an object (this list will likely contain other objects/forms), you have to extend the generated form to add the necessary setters for indexed properties. For example, if you have an addresses List on a PersonForm, you would need the following in order to edit those addresses in Struts.
setAddresses(int index, Object address) {
|
The worst part is that you need to populate the addresses list with a bunch of empty AddressForm objects before Struts' auto-population will succeed. If you were coding the PersonForm by hand, you could code a reset() method such as the following:
public void reset(ActionMapping mapping, HttpServletRequest request) {
|
Now for the best part - I figured out how to generate this code with XDoclet, so any lists on your Forms will be indexed-property ready. By using <nested:iterate> in your JSP, you can easily CRUD you indexed properties. Pretty slick IMHO. The template is a bit much to put on this site, and it's long lines won't fit in a <pre> - so you can temporarily view the template here. I'll add a link to it in AppFuse's CVS once it shows up there. One thing you'll notice in this template is a little Velocity-lovin':
<XDtVelocity:generator> #set( $method = $currentMethod.name) ## trim off the 'get' #set( $objectName = $method.substring(3, $method.lastIndexOf('s'))) </XDtVelocity:generator>
Thanks to Erik on Merrick's blog for the quick Velocity/XDoclet howto. It was especially helpful since the XDoclet site has no documentation on this feature.
For all you my framework is better junkies - a clear explanation of how your framework handles indexed properties would be appreciated.
Posted by Jose Nyimi on June 26, 2004 at 11:35 AM MDT #
Posted by Matt Raible on June 26, 2004 at 12:47 PM MDT #