Announcement Announcement Module
Collapse
No announcement yet.
How do I show formView with the command object refreshed? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I show formView with the command object refreshed?

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

  • #2
    Use the spring:bind tag in your html. Here's an example where I have a SELECT tag that displays Admin or Waitlist.
    Code:
    <spring&#58;bind path="sifd.view">
    <select name="view">
    <option value="waitlistView"
    <c&#58;if test="$&#123;status.value=='waitlistView'&#125;">
    selected="true"
    </c&#58;if>
    >Waitlist</option>
    <option value="adminView"
    <c&#58;if test="$&#123;status.value=='adminView'&#125;">
    selected="true"
    </c&#58;if>
    >Admin</option>
    </select>
    </spring&#58;bind>
    In the spring docs look at the form controllers and the stuff about the command object.

    I'm a spring newbie so there may be a better way to do this.

    Comment

    Working...
    X