Wednesday, May 7, 2008

formdef.plugin.util.FormUtils-------Automating Conversion from Action Form to Java Business Objects/Value Objects

FormUtils.setFormValues()


   
FormUtils.setFormValues() can be used to initialize a form bean with values from a business object:

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

The first parameter identifies the form definition that will be used.
The second parameter is the business object which contains the values that will be used to populate the form bean.
The last three parameters are the current Action object, the current action mapping, and the request being processed.

FormUtils.setFormValues() returns the populated form bean. This can then be placed by the caller in the proper scope with the proper name so that Struts can find it when rendering an HTML form.

 

  FormUtils.getFormValues()


   
FormUtils.getFormValues() can be used to create a populated business object from a form bean:

    Employee employee = (Employee)
            FormDefUtil.getFormValues(form, this, mapping, request);
            

The first parameter is the form passed by Struts to the action object.
The next three parameters are the current Action object, the current action mapping, and the request being processed.

getFormValues() returns the business object populated with values from the form bean. If a factory is associated with the form definition, it is called to create the business object that will be populated. Otherwise, the business object's no-arg constructor will be used to create the object.

No comments:

Post a Comment