我使用Spring 3.x并尝试在下拉值改变时提交表单 - 这样控制器可以正确地确定调用哪个方法:
<form:form modelAttribute="myContainer" action="/credits/processAssignment.ntwx"
method="post" name="assignmentsForm">
<form:select path="currentCreditId" width="400" onchange="submit()">
<c:forEach items="${creditIds}" var="creditId">
<form:option value="${creditId}" >
</c:forEach>
</form:option>
</form:select>
...other controls and submit buttons
</form:form>
当选择/下拉值发生变化时,我想让它在控制器中调用此方法:
@RequestMapping(value = "/credits/processAssignment.ntwx", method = RequestMethod.POST,
params="creditIdChanged" )
public ModelAndView creditIdChanged( HttpServletRequest request, HttpServletResponse
response, @ModelAttribute("myContainer") MyContainer myContainer, ModelMap model)
我认为关键是要弄清楚如何从下拉列表中传递参数'creditIdChanged'。我在页面上有一些提交按钮,它们通过名称属性传递参数:
<input type="submit" name="addRow" value="Add Row" class="button" />
这将传递参数'addRow',因此很容易将此提交映射到控制器方法。使用以下形式的name ='creditIdChanged'或id ='creditIdChanged':select不会将creditIdChanged作为参数传递。
任何建议?