JamesGSmith code was based on mine and I have merged it into one now.
I dont think it is really necessary to use the SimpleMultiActionFormController because you really are not doing much with the form command objects binds you only have one parameter you are interested in. So there is easier ways to do this.
But as an example using MultiActionController with a submit parameter resolver, ill give it a go
Code:
public class JamesWExampleMultiActionFormController extends MultiActionFormController {
protected Object formBackingObject(HttpServletRequest request)
throws Exception {
//form whatever the backing object is
Object obj = new Object();
return obj;
}
protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception {
Map model = new HashMap();
Set deps = businessLogic.getAllDepartments();
model.put("departments", deps);
return model;
}
private IDepartmentBusiness businessLogic;
public ModelAndView deleteDepartment(HttpServletRequest request, Object command, BindException errors) throws Exception {
String departmentId = request.getParameter("departmentId");
businessLogic.deleteDepartment(Integer.parseInt(departmentId));
return null;
}
public ModelAndView addDepartment(HttpServletRequest request, Object command, BindException errors) throws Exception {
String departmentId = request.getParameter("departmentId");
businessLogic.addDepartment();
return null;
}
public ModelAndView editDepartment(HttpServletRequest request, Object command, BindException errors) throws Exception {
String departmentId = request.getParameter("departmentId");
Map model = new HashMap();
model.put("departmentId", departmentId);
return new ModelAndView(new RedirectView("editDepartment.htm"), model);
}
}
Code:
<bean id="submitActionParamResolver" class="com.lakeside.springframework.web.servlet.mvc.multiaction.SubmitParameterPropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="_addDepartment">addDepartment</prop>
<prop key="_deleteDepartment">deleteDepartment</prop>
<prop key="_editDepartment">editDepartment</prop>
</props>
</property>
</bean>
<bean id="exampleFormController" class="com.lakeside.springframework.web.servlet.mvc.multiaction.JamesWExampleMultiActionFormController ">
<property name="methodNameResolver"><ref bean="submitActionParamResolver"/></property>
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>command</value></property>
<property name="formView">listDepartments<value></value></property>
</bean>
Code:
<%@ include file="/WEB-INF/jsp/spring/IncludeTop.jsp" %>
<P>
<H2>Simple Entities:</H2>
<TABLE border="1">
<TR><FORM method="POST" action="<c:url value="listDepartments.htm"/>">
<TD><B>Department:</B>
<SELECT name="departmentId" id="departmentId">
<c:forEach var="department" items="${departments}">
<c:if test="${department.id == department.id}">
<OPTION selected="<c:out value="${model.department.id}"/>"
value="<c:out value="${department.id}"/>">
<c:out value="${department.name}"/></OPTION>
</c:if>
<c:if test="${model.department.id != department.id}">
<OPTION value="<c:out value="${department.id}"/>">
<c:out value="${department.name}"/></OPTION>
</c:if>
</c:forEach>
</SELECT></TD>
<TD><INPUT type="submit" name="_editDepartment" value="Edit"/></TD>
<TD>
<INPUT type="submit" name="_addDepartment" value="Add"/></TD>
<TD>
<INPUT type="submit" name="_deleteDepartment" value="Delete"/>
</FORM></TD>
</TR>
</TABLE>
<P>
<BR>
<%@ include file="/WEB-INF/jsp/spring/IncludeBottom.jsp" %>
something like this may work for you