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 might write a handler method called handleRegister
, which is 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 might write methods called handleRegister
, handleUpdate
, and handleChangePassword
. The individual forms use the appropriate method. 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: 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 wrote that resets the form data:
public boolean handleCancel(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse) throws ServletException, IOException { resetMyFormData(); return super.handleCancel(pRequest, pResponse); }