2015-04-24 27 views
0

我有一個單獨的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表單)。也許,我不能在另一個表單選項中使用表單,但如果這只是選項,我會繼續前進,然後再試一次。一個

+0

把一切都放在一個表單中? –

+0

但他們的模型屬性是不同的,我怎麼能在這種情況下? – rakeeee

+0

將它們綁定到同一個Model對象。如有必要,在兩個現有模型對象上創建一個包裝,並將各個字段綁定到這些嵌套屬性,例如obj1.abc,obj2.xyz –

回答

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(); 
    }); 
});