使用单个按钮在弹簧中进行多种形式到单一动作

时间:2015-04-24 07:28:54

标签: javascript spring jsp

我有一个单独的jsp,有两种弹簧形式可用。

<form:form modelAttribute="obj1" action="/some">
                here i get the list of values and show then in dropdown.
</form:form>

<form:form modelAttribute="obj2" action="/some">
                here i have some other things like table etc and **a submit button**.
</form:form>

obj1和obj2都是模型对象,并由两个数据库调用填充。

@RequestMapping("some")
public ModelAndView somemethod(){
   return "modelandview";
 }

现在,如何在按下提交按钮时在此控制器操作的下拉列表中检索所选值。现在,我能够从另一种形式(例如obj2形式)获取数据。可能,我不能在另一个表单选项中使用表单,但如果这只是选项,我将继续并再试一次。

1 个答案:

答案 0 :(得分:1)

为每个表单添加一个类并删除提交按钮,只需在表单后添加一个输入:

<form:form class="formSubmit" modelAttribute="obj1" action="/some">
    here i get the list of values and show then in dropdown.
</form:form>
<form:form class="formSubmit" modelAttribute="obj2" action="/some">
    here i have some other things like table etc.
</form:form>
<input id="submit" type="button" value="Submit">

然后在提交按钮中添加一个jQuery处理程序,它将遍历每个表单并提交

$('#submit').click(function() {
    $('.formSubmit').each(function() {
        $(this).submit();
    });
});
相关问题