Raible's Wiki
Raible Designs AppFuseHomepage- Korean - Chinese - Italian - Japanese QuickStart Guide User Guide Tutorials Other ApplicationsStruts ResumeSecurity Example Struts Menu
Set your name in
UserPreferences
Referenced by
JSPWiki v2.2.33
Hide Menu |
This is version 3.
It is not the current version, and thus it cannot be edited. One of the things I've recently added to AppFuse is the ability to generate indexed-property-ready ActionForms using XDoclet. It's pretty simple really - if you're using XDoclet, you can add it too with the following steps:
/** * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, * javax.servlet.http.HttpServletRequest) */ public void reset(ActionMapping mapping, HttpServletRequest request) { // reset any boolean data types to false <XDtStrutsForm:forAllFormFields> <XDtType:ifIsOfType value="return-type" type="java.lang.Boolean,boolean" extent="concrete-type"> this.<XDtMethod:propertyName/> = false; </XDtType:ifIsOfType> </XDtStrutsForm:forAllFormFields> <XDtClass:ifHasClassTag tagName="struts.form" paramName="indexedProperties" value="true"> <XDtStrutsForm:forAllFormFields> <XDtType:ifIsOfType value="return-type" type="java.util.List,java.util.Set" extent="concrete-type"> <XDtVelocity:generator> #set( $method = $currentMethod.name) ## trim off the 'get' #set( $objectName = $method.substring(3, $method.lastIndexOf('s'))) </XDtVelocity:generator> this.<XDtMethod:propertyName/> = org.apache.commons.collections.ListUtils.lazyList(new java.util.ArrayList(), new ObjectFactory("<XDtVelocity:getVariable name="objectName"/>")); </XDtType:ifIsOfType> </XDtStrutsForm:forAllFormFields> </XDtClass:ifHasClassTag> } <XDtClass:ifHasClassTag tagName="struts.form" paramName="indexedProperties"> /** * <code>ObjectFactory</code> - used if indexed properties exist on this form. * * @see org.apache.commons.collections.ListUtils */ class ObjectFactory implements org.apache.commons.collections.Factory { private String name; /** * Create a new instance of the specified object */ public Object create() { Class c = null; try { c = Class.forName("org.appfuse.webapp.form." + name + "Form"); return c.newInstance(); } catch (Exception e) { System.err.println("Error instantiating class: " + c.getName()); throw new RuntimeException(e); } } public ObjectFactory(String name) { this.name = name; } } </XDtClass:ifHasClassTag>
This stuff works really slick with Hibernates ability to Lazy load objects. In AppFuse the BaseAction has a convertLists() method that allows easy conversion from your indexed Forms to indexed POJOs and vise-versa.
|