Home
Download
Manual
Nested Beans
Mailing Lists
FAQ
| ## FormDef Struts Form Definition Plug-In FormDef is a Struts plug-in designed to ease the work associated with ActionForms in Struts. FormDef provides the following to a Struts application: Generate DynaActionForm definitions based on your business objects Data formatting support to html form controls to contain formatted text Conversion methods to format and parse data between your form and business object Locale support to allow the same form to be used in different locales using different data formats Extensions to allow both form definitions and form validations to reside in one XML How it works 1. Declare the plugin in your struts-config.xml file. Of course you'll need the formdef.jar in your WEB-INF/lib or whereever you like to keep your struts.jar.
        <plug-in className="formdef.plugin.FormDefPlugIn">
            <set-property property="defnames"
                value="/WEB-INF/form-defs.xml"/>
        </plug-in>
2. Create a form-defs.xml in your WEB-INF folder (or whereever you wanna place it). Copy the following code there, then replace the form's name with the name you want, and specify the full class name of the business object you want a formbean for.
        <form-definition>
            <formset>
                <form name="myForm"
                    beanType="com.my.dto.MyBean"/>
            </formset>
        </form-definition>
That's it for declaring your bean. You can now start using your DynaActionForm in your code. The fields of your formbean will match the fields of your bean. Optionally, you can use the included FormUtils class to convert between your business object and form bean. For pre-populating your form with your business object, see FormUtils.setFormValues(). To populate your business object with your form, see FormUtils.getFormValues().