My controller extends the SimpleFormController and my formBackingObject returns a list of objects that the user can select and delete. My onSubmit iterrates through the selected ids and calls the delete function. If it encounters an exception it adds an error to the errors and continues to delete the remaining selected objects. I then check to see if there where any errors and if so return the formView. The problem is that my formView shows all the objects even the ones that were successfully deleted. In other words, the formBackingObject does not get called again to refresh the list. I have tried a bunch of different things including calling the formBackingObject from inside my onSubmit but it doesn't seem to work.
Here's what I have tried so far:
//I have tried calling the formBackingObject
if(errors.hasErrors())
{
formBackingObject(request);
model.putAll(errors.getModel());
return new ModelAndView(getFormView(), model);
}
//I have aslo tried return the successView with the errors as a model
//This works in that it returns a refreshed list but the error messages get lost
if(errors.hasErrors())
{
formBackingObject(request);
model.putAll(errors.getModel());
return new ModelAndView(getSuccessView(), model);
}
Here's my bean def
<bean id="defectDefListController" class="com.timestock.tess.web.controllers.DefectDe fListController">
<property name="formView"><value>defectDefList</value></property>
<property name="successView"><value>redirect:defectDefList.h tml</value></property>
</bean>
My formBackingObject
protected Object formBackingObject(HttpServletRequest request)
throws Exception
{
Long pId = RequestUtils.getRequiredLongParameter(request, "pId");
TranSetDef tranSetDef = tranSetDefDao.get(pId);
defectDefList = defectDefDao.findByTranSetDef(tranSetDef);
return defectDefList;
}
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception
String[] idList = request.getParameterValues("idList");
if (idList != null && idList.length > 0)
{
for (int i = 0; i < idList.length; i++)
{
Long id = Long.parseLong(idList[i]);
DefectDef defectDef = defectDefDao.get(id);
try{
defectDefDao.delete(defectDef);
}
catch(PermissionDeniedException ex)
{
errors.reject(ex.getMessageKey(), ex.getMessageArgs(), ex.getMessage());
logger.error(ex);
}
}
Map model = new HashMap();
model.put("pId", RequestUtils.getRequiredLongParameter(request, "pId"));
if(errors.hasErrors())
{
model.putAll(errors.getModel());
return new ModelAndView(getFormView(), model);
}
return new ModelAndView(getSuccessView(), model);
}


Reply With Quote