Home
Download
Manual
Nested Beans
Mailing Lists
FAQ

FAQ



  How do I add the plugin?

    You need to add a <plug-in> entry in your struts config file just as you would for Tiles and Validator.
    <plug-in className="formdef.plugin.FormDefPlugIn">
        <set-property property="defnames"
            value="/WEB-INF/form-defs.xml"/>
    </plug-in>
        


  How do I tell FormDef to create an ActionForm for my business object?

    Add a <form> entry to in your form definition xml:
    <form-definition>
        <formset>
            <form name="myForm"
                beanType="com.my.dto.MyBean"/>
        </formset>
    </form-definition>
            
When the plugin gets executed, it will create a DynaActionForm containing the String fields for each property of MyBean.


  How do I initialize the form with values from by business object in my Action class?

    Use FormDefUtil.setFormValues():
    DynaActionForm dynaForm = (DynaActionForm) 
            FormDefUtil.setFormValues("employeeForm", employee,
                    this, mapping, request);
            


  How do I retrieve the values from the form in my Action class?

    Use FormDefUtil.getFormValues() (imagine that!):
    Employee employee = (Employee)
            FormDefUtil.getFormValues(form, this, mapping, request);
            


  What data types have built-in support?

    All primitive data types are supported, as well as String and Date types.


  How do I format my fields?

    Specify conversion parameters for the fields that need formatting.
    <form-definition>
        <formset>
            <form name="myForm"
                beanType="com.my.dto.MyBean">

                <field property="myDouble"/>
                    <converter param="###,###,##0.00"/>
                </field>
            </form>
        </formset>
    </form-definition>
    
DecimalFormat format strings are used for numeric fields, and DateFormat format strings are used for java.util.Date, java.sql.Date, and java.sql.Timestamp. See the Converters section in the FormDef manual for more information.


  How are dates formatted? Is there a default date format used?

    There are no default formats defined for dates. If you have Date fields, you must specify the format for each of them or define a global format that will be applied for all fields of a particular type (like java.util.Date):
    <global-converters>
        <global-converter for="property-type"
            target="java.util.Date"
            param="MM/dd/yyyy"/>
    </global-converters>
    


  How do I add support for my own class?

    There are two ways. One is to do perform the conversion yourself in your Action class. You can do this after you call FormDefUtil.getFormValues() or setFormValues().
If you use your form in multiple places, a better option might be to write your own Converter. It's very simple. You'll be provided a ConversionContext object which will contain the value to convert and the Class to which it should be converted to. You just return the result of the conversion.


  How do I define a form bean that contains one or more fields than my JavaBean?

    You just need to add your new field within your form declaration:
    <form name="myForm"
        beanType="com.my.dto.MyBean">
        <field name="selectedButton"/>
    </form>
        
The above declaration will create the myForm form bean with all the fields of MyBean as well as a field for selectedButton.


  I want to use the combined FormDef and Validator XML format, but not all of my forms need to be validated. How can I tell Validator to ignore those forms?

    Use the validate="false" attribute for your form:
    <form name="mySimpleForm" validate="false">
        <field name="someField"/>
    </form>
    
When validate="false" is specified, the formdef validator plugin extension will not pass that form definition to the Validator engine.


  I have a form whose fields mostly need to be validated, but not all. How can I tell Validator to ignore those fields?

    The validate="false" also works for fields:
    <field name="someField" validate="false"/>
    


  How do I use two (or more) different date formats for different fields in different forms?

    You can create named <global-converter>s and use those converter names to select what format you want for which fields.
    <form-definition>
        <global-converters>
            <!-- this would be your default format applicable to all Date fields -->
            <global-converter for="property-type"
                target="java.util.Date"
                param="MM/dd/yyyy"/>

            <!-- define other date conversion parameters and assign names to them -->
            <global-converter for="converter-name"
                target="myDateFormat2"
                param="MMM-yyyy"/>

            <global-converter for="converter-name"
                target="myDateFormat3"
                param="yyyy/MM/dd"/>

        </global-converters>
        <formset>
            <form name="myForm"
                beanType="com.my.dto.MyBean">

                <!-- date2 uses the second format -->
                <field property="date2"/>
                    <converter name="myDateFormat2"/>
                </field>

                <!-- date3 uses the third format -->
                <field property="date3"/>
                    <converter name="myDateFormat3"/>
                </field>

                <!-- MyBean's other fields will all use the default converters and formats -->
                <!-- there might be a date1 which uses the first format, and that -->
                <!--   would already be covered by the global Date converter -->
            </form>

            <!-- myOtherForm's date fields will all use the default MM/dd/yyyy -->
            <form name="myOtherForm"
                beanType="com.my.dto.MyOtherBean"/>
        </formset>
    </form-definition>