2011-11-17 23 views
0

我有一個春天的應用程序,我想添加一個登錄功能。我想將登錄表單放入網站的標題中。這意味着它將包含在多個頁面中。在定義表單提交給的控制器時,我該怎麼指定formView嵌套的速度模板與春天formView

是否可以指定包含在標題中的登錄模板(包含在每個標題中:-))作爲formView

感謝您的幫助。如果有什麼不清楚的地方比我很樂意提供更多的細節或顯示代碼。

回答

0

沒關係。我意識到Velocity模板是否包含在另一個文件中並不重要。我已將此添加到模板:

<form method="POST"> 
#springBind("credentials.*") 

和我的控制器看起來像這樣:

@Controller 
public class SplashController implements Serializable { 

    protected final Log logger = LogFactory.getLog(getClass()); 
    private static final long serialVersionUID = 7526471155622776147L; 

    @ModelAttribute("credentials") 
    public LoginCredentials getFormBean() { 
     return new LoginCredentials(); 
    } 

    @RequestMapping(method = RequestMethod.GET) 
    public String showForm() { 
     logger.info("In showForm method of SplashController"); 
     return "splash"; 
    } 

    @RequestMapping(method = RequestMethod.POST) 
    public ModelAndView onSubmit(LoginCredentials credentials, BindingResult bindingResult) { 

     logger.info("In onSubmit method of SplashController"); 
     logger.info("Username = " + credentials.getUsername()); 
     logger.info("Password = " + credentials.getPassword()); 
     ModelAndView modelAndView = new ModelAndView("home"); 
     return modelAndView; 

    } 

} 

和它的作品。