开发者

SpringMVC Command Object

I have a small doubt with SpringMVC's command object. So the problem is, I have couple of forms which I am going to use in multiple pages (Around 17). I decided to make these two forms as JSP's and include them in the parent JSP's. The problem I am facing is that the textfields and dropdown's aren't populating with the data which is passed 开发者_Python百科on from the server using Command object.

Lets call the Parent JSP as parent.jsp and than two included JPS's(which have the forms) as child1.jsp and child2.jsp. The controller for parent.jsp sets a ModelAttribute with name previousSales and returns the view as abc/parent where abc is the folder. (WEB-INF/jsp/abc/parent). My question is how do I make the model attribute available to the included JSP's?


The Command object should be part of your handler method calls, as follows:

@RequestMapping("/somepath/foo/do")
public String someHandlerMethod(
   @ModelAttribute("commandObject") CommandObject commandObject,
   Model model, 
   BindingResult result) {
     ...processing...
     return("some.jsp");
}

On your JSP, use the Spring Forms TLD for the form fields, and the Command object will be bound to the form fields.


@RequestMapping("/somepath/foo/do")
public String someHandlerMethod(
   @ModelAttribute("commandObject") CommandObject commandObject,
   Model model, 
   BindingResult result) {
     ...processing...
     return("some.jsp");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜