You can create handler methods that are associated with a form’s submit button in the same way that form fields are associated with specific properties. Submit handler methods are particularly powerful, because the tags that implement them are processed after tags that use other input types so you can use them to evaluate the form as a whole and take appropriate actions. For example, you could write a handler method called handleRegister, which would be invoked when the user clicks the “Register now” button created by this tag:

<dsp:input type="submit" value="Register now"
  bean="MyFormHandler.register"/>

Your form handler can have any number of submit handler methods that each handle form submissions differently. For example, if your site has registration, update, and change password forms, you could write methods called handleRegister, handleUpdate, and handleChangePassword. The individual forms would then use whichever method is appropriate for them. For example, the tag for the submit button on the change password form might be:

<dsp:input type="submit" value="Change Password"
  bean="MyFormHandler.changePassword"/>
Extending the handleCancel Method

The atg.droplet.GenericFormHandler class (and any subclass of GenericFormHandler you write) includes a handleCancel method for implementing “Cancel” buttons in forms. This method redirects to the URL specified in the form handler’s cancelURL property. Typically this property is set to the current page, so that clicking “Cancel” just redisplays the form page. If the form handler component is request scoped, this creates a new instance of the form handler object, and reinitializes the form data.

Note that if your form handler component is session scoped (see Form Handler Scope), this reinitialization does not occur. In this case you need to extend the handleCancel method of its class so it resets the appropriate form data. In the following example, the handleCancel method calls a method you’ve written that resets the form data:

public boolean handleCancel(DynamoHttpServletRequest pRequest,
               DynamoHttpServletResponse pResponse)
       throws ServletException, IOException
   {
     resetMyFormData();
     return super.handleCancel(pRequest, pResponse);
   }

 
loading table of contents...