简体   繁体   English

如何将formBean集成到Spring MVC中?

[英]how can I integrate formBean to my Spring MVC?

My application is using Spring MVC. 我的应用程序正在使用Spring MVC。 On the way from the Controller to the view we are taking adventage of this framwork by creating a bean of the model that is used to display the relevant properties through the JSP. 从Controller到视图的过程中,我们通过创建模型的Bean来利用该框架,该Bean用于通过JSP显示相关属性。 On the way back however, meaning after submitting a form back to the controller, it is using a raw HTTPRequest instead of a structured formBean. 但是,在返回的过程中,这意味着在将表单提交回控制器之后,它使用的是原始HTTPRequest而不是结构化的formBean。

I think that this is a disadvantege so I am looking for way to insert this to our MVC model. 我认为这是一个缺点,因此我正在寻找将其插入到我们的MVC模型中的方法。 I saw in this link some way that Spring MVC handles it. 我在该链接中看到了Spring MVC处理它的某种方式。 by adding to the JSP binding such as: 通过添加到JSP绑定,例如:

<spring:bind path="command">  <font color="red">    <b><c:out value="${status.errorMessage}"/></b>  
</font>
</spring:bind>

and to the controller: 并发送给控制器:

 protected ModelAndView onSubmit(Object command) throws ServletException  
{    Widget widget = (Widget) command;
...
}

But this solution is not good for our implementation - I don't want to add anything to the JSP and in addition . 但是这种解决方案对我们的实现不利-我不想在JSP中添加任何东西。 some of the parameters that are added to the httprequest are done in javascript code. 添加到httprequest的某些参数是用javascript代码完成的。 Therefore I am looking for a solution that can create formBean out of the form parameters while the mapping is not defined on the JSP but elsewhere (in some dedicated xml obviously). 因此,我正在寻找一种解决方案,该解决方案可以在表单参数不是在JSP上而是在其他地方(显然是在某些专用xml中)定义的情况下,根据表单参数创建formBean。

Any ideas? 有任何想法吗?

The simplest way to use a form (command) bean in Spring is to write a controller that extends SimpleFormController. 在Spring中使用表单(命令)bean的最简单方法是编写一个扩展SimpleFormController的控制器。

A quick Google shows a number of basic tutorials - for example: 快速的Google展示了许多基本教程-例如:

http://www.vaannila.com/spring/spring-simple-form-controller-1.html http://www.vaannila.com/spring/spring-simple-form-controller-1.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM