Вы находитесь на странице: 1из 2

14th feb 2011

WebUtils.hasSubmitParameter(request, "_edit")
which can deal with image buttons as well.

and thefollowing........

public class MultiSubmitActionController extends AbstractController{


private String editView;
private String addView;
private String deleteView;
public void setAddView(String addView) {
this.addView = addView;
}
public void setDeleteView(String deleteView) {
this.deleteView = deleteView;
}
public void setEditView(String editView) {
this.editView = editView;
}
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
Long id = null;
if(request.getParameter("id")!=null){
id = new Long(request.getParameter("id"));
}
if(request.getParameter("_edit")!=null){
return new ModelAndView(editView, "id", id);
}
if(request.getParameter("_add")!=null){
return new ModelAndView(addView);
}
if(request.getParameter("_delete")!=null){
return new ModelAndView(deleteView, "id", id);
}
return new ModelAndView("selectEntityRedirect");
}

}
Then in my servlet context, I plug in a RedirectView for each action...
<bean id="departmentAction"
class="com.sccc.locknload.web.spring.namedEntities.MultiS ubmitActionController"
>
<property name="editView"><value>departmentEditRedirect</value></property>
<property name="addView"><value>departmentAddRedirect</value></property>
<property name="deleteView"><value>departmentDeleteRedirect</value></property>
</bean>
Each RedirectView points to each of the following controllers through the UrlMap
ping...
<bean id="editDepartmentForm" class="com.sccc.locknload.web.spring.namedEntities
.depart ment.EditDepartmentForm">
<property name="formView"><value>departmentForm</value></property>
<property name="successView"><value>selectEntityRedirect</value></property>
<property name="locknload"><ref bean="locknload"/></property>
</bean>
<bean id="addDepartmentForm" class="com.sccc.locknload.web.spring.namedEntities.
depart ment.AddDepartmentForm">
<property name="formView"><value>departmentForm</value></property>
<property name="successView"><value>selectEntityRedirect</value></property>
<property name="locknload"><ref bean="locknload"/></property>
</bean>
<bean id="deleteDepartmentForm" class="com.sccc.locknload.web.spring.namedEntiti
es.depart ment.DeleteDepartmentForm">
<property name="formView"><value>deleteDepartmentForm</value></property>
<property name="successView"><value>selectEntityRedirect</value></property>
<property name="locknload"><ref bean="locknload"/></property>
</bean>
Finally, in the JSP, which is actually composed of several of these, the form ju
st calls the url that is mapped to its MultiSubmitActionController - In this cas
e /departmentAction.htm ....
<TABLE border="1">
<TR valign="top"><FORM method="GET" action="<c:url value="/departmentAction.htm"
/>">
<TD align="right"><B>Departments:</B></TD>
<TD<SELECT name="id">
<c:forEach var="department" items="${model.departmentTypes}">
<c:if test="${model.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.nam
e}"/></OPTION>
</c:if>
</c:forEach>
</SELECT></TD>
<TD><INPUT type="submit" name="_edit" value="Edit"/></TD>
<TD><INPUT type="submit" name="_add" value="Add"/></TD>
<TD><INPUT type="submit" name="_delete" value="Delete"/></TD></FORM>
</TR>
</TABLE>

Вам также может понравиться