Results 1 to 2 of 2

Thread: How do I show formView with the command object refreshed?

  1. #1

    Default 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);
    }
    cheers,
    Lili

  2. #2
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default

    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.

Similar Threads

  1. Replies: 4
    Last Post: Oct 13th, 2005, 07:14 AM
  2. How to show a checkbox list
    By cacho in forum Web
    Replies: 4
    Last Post: Aug 30th, 2005, 04:56 AM
  3. No Show Graph option
    By Christian in forum SpringSource Tool Suite
    Replies: 4
    Last Post: Aug 5th, 2005, 05:00 PM
  4. Replies: 11
    Last Post: Jul 21st, 2005, 10:46 AM
  5. Replies: 0
    Last Post: Apr 26th, 2005, 08:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •