Spring MVC Wizard Controller

Source: Internet
Author: User

Overview

Suppose that a system in the user registration module needs to distinguish between the general user and advanced users, the general user provided the simplest information, through a small form can be fixed. However, for customers who need to be registered as senior users, the forum wants them to provide detailed registration information, in addition to the user name, password, email the simplest information, but also need to provide residential address, telephone and hobbies such as survey information. It is not a good idea to let the registrant fill in all this information at once through a large form, and most potential users will not hesitate to sign up when they see a "super form" with such a grim face. At this time through a wizard-type form to allow users to fill out the registration information will be a sensible solution, although the need to fill in the amount of data, but the psychological experience tells us that the user will be in the first feeling simple psychological hint under the "wheat trap" we set up slowly.

The information required for advanced user registration is broken down into 3 forms and step-by-Step through the wizard:

1 fill in the user name, password, email and other general information;

2 fill in the address, telephone and other contact information;

3 to fill in the user's interests and hobbies of the survey information.

Developing a wizard-style form in other MVC frameworks is not easy, because you need to consider a list of issues such as forward, back, exit, form-step checking, data maintenance, and more. Fortunately, in spring MVC, you don't have to think about the details of the underlying workflow, Abstractwizardformcontroller has prepared the Workflow for the wizard form and opened the steps that need to be determined. You just need to extend the out-of-the-box abstractwizardformcontroller through very little work, a powerful wizard form is done.

We intend to complete the operation of advanced user registration through the following page processes:

Figure 1 Registering the Advanced User Wizard page process

To create a wizard controller that registers advanced users

We build a wizard controller that must inherit the Abstractwizardformcontroller class, and Fulluserregistercontroller is responsible for providing the Basic Wizard controller for the registered advanced user, whose code looks like this:

Code Listing 1 Fulluserregistercontroller: Wizard Controller

package com.baobaotao.web.user;

import org.springframework.web.servlet.mvc.AbstractWizardFormController;
public class FullUserRegisterController extends AbstractWizardFormController {
private String cancelView; ① 点击取消后转向的视图(逻辑视图名)
private String successView; ② 向导最终处理成功后转向的成功页面
private BbtForum bbtForum;
public void setBbtForum(BbtForum bbtForum) {
this.bbtForum = bbtForum;
}

③ is responsible for handling the final form submission action

protected ModelAndView processFinish(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
FullUser fullUser = (FullUser) command;
bbtForum.registerFullUser(fullUser);
③-1转向welcome.jsp页面
return new ModelAndView(getSuccessView(), "fullUser", fullUser);
}
④负责处理取消的动作
protected ModelAndView processCancel(HttpServletRequest request, HttpServletResponse
response, Object command, BindException errors) throws Exception {
return new ModelAndView(getCancelView());④-1转向main.jsp页面
}
//省略get/setter
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.