A form handler component should be either request- scoped or session-scoped. A request scoped form handler exists for the duration of the request. Consider a form that is held in one page. By clicking the submit button, the user makes a request that, in turn, creates an instance of the form handler. The configured values in the form handler’s properties file are used. You can override the values of these properties using a dsp:setvalue or dsp:input tags. Once a user submits the form, the form handler processes the data.

When your form handler spans several pages, such as in a multi-page registration process, you want values entered in each page to stay persist until the final submission. You could implement the registration process with a request-scoped form handler by designing it to support a redirect: make data from page one available to page two. Because you can only use one redirect per form handler instance, if your registration process requires more than two pages, a request-scoped form handler won’t do.

One solution is to make your form handler session-scoped. The main disadvantage to this option is that your form would exist for the entire user session, and using many such form handlers will consume unnecessary memory. When you use session-scoped form handlers, you must remember to reset or clear values between uses of the form handler because values will remain in effect throughout the entire session. It’s especially important to clear error messages to ensure they don’t appear in other forms where they aren’t relevant.

Another option is to provide a separate, request-scoped form handler instance to each form page and associate all registration form pages, for example, to a shared, session-scoped component. With each form submission, the form handler automatically copies the data to the session-scoped component. That way, if you want page five to hold a list of data entered in pages one through four for validation, you need only reference the relevant properties in the session-scoped component. This technique offers the persistence of a session-scoped form handler and data refresh provided in a request-scoped form handler.

You’ll find this technique especially helpful in implementing search form handlers when you want to search results available for future reference. In order to implement this behavior, design your form handler’s submit handler method to retrieve the session-scoped component and set specific properties on it.

 
loading table of contents...