Topic: 关于Spring SimpleFormController workflow的问题

  Print this page

1.关于Spring SimpleFormController workflow的问题 Copy to clipboard
Posted by: yeafee
Posted on: 2006-01-06 15:31

在看Spring jpetstore源码新帐号注册时有bean(AccountFormController)继承自SimpleFormController,部份源代码如下,不明此Bean的工作流程是怎样的,请指点些,

public class AccountFormController extends SimpleFormController {
  ...
  private PetStoreFacade petStore;

  public AccountFormController() {
    setSessionForm(true);
    setValidateOnBinding(false);
    setCommandName("accountForm");
    setFormView("EditAccountForm");
  }

  public void setPetStore(PetStoreFacade petStore) {
    this.petStore = petStore;
  }

  protected Object formBackingObject(HttpServletRequest request)
throws Exception {
    UserSession userSession = (UserSession)WebUtils.
getSessionAttribute(request, "userSession");
    if (userSession != null) {
    return new AccountForm(this.petStore.getAccount(userSession.
getAccount().getUsername()));
    }
    else {
      return new AccountForm();
    }
  }

  protected void onBindAndValidate(HttpServletRequest request,
Object command, BindException errors)
      throws Exception {

    AccountForm accountForm = (AccountForm) command;
    Account account = accountForm.getAccount();

    if (request.getParameter("account.listOption") == null) {
      account.setListOption(false);
    }
    if (request.getParameter("account.bannerOption") == null) {
      account.setBannerOption(false);
    }

    errors.setNestedPath("account");
    getValidator().validate(account, errors);
    errors.setNestedPath("");

    ...
  }

  protected Map referenceData(HttpServletRequest request) throws Exception {
    Map model = new HashMap();
    model.put("languages", LANGUAGES);
    //model.put("categories", this.petStore.getCategoryList());
    return model;
  }

  protected ModelAndView onSubmit(
  HttpServletRequest request, HttpServletResponse response,
Object command, BindException errors)throws Exception {
    ...
  }
}

2.Re:关于Spring SimpleFormController workflow的问题 [Re: yeafee] Copy to clipboard
Posted by: floater
Posted on: 2006-01-06 21:13

The flow is stated in the book java development with the spring framework(P471). It's a little bit messy. For simple cases, I just implement Controller interface directly. For complex cases, I use this one.

3.Re:关于Spring SimpleFormController workflow的问题 [Re: yeafee] Copy to clipboard
Posted by: auauau
Posted on: 2006-01-19 09:46

正如 floater 说得那样,但如果你没有这本书,我给你发两张图,你可以先看一下。

(缩略图,点击图片链接看原图)

4.Re:关于Spring SimpleFormController workflow的问题 [Re: yeafee] Copy to clipboard
Posted by: auauau
Posted on: 2006-01-19 09:48



(缩略图,点击图片链接看原图)

5.Re:关于Spring SimpleFormController workflow的问题 [Re: yeafee] Copy to clipboard
Posted by: yeafee
Posted on: 2006-01-25 11:02

BeerSuN034,多谢.呵呵


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923