Announcement Announcement Module
Collapse
No announcement yet.
Neither referenceData nor formBackingObject are called Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Neither referenceData nor formBackingObject are called

    I implemented several SimpleFormController without any problems, but this time my referenceData and formBackingObject methods are not being called and I have no idea why. Here is a simplified version of my Controller:
    Code:
    ...
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.log4j.Logger;
    import org.springframework.web.servlet.mvc.SimpleFormController;
    import org.springframework.web.servlet.ModelAndView;
    
    public class MyController extends SimpleFormController {
    
      private static Logger LOGGER = Logger.getLogger(MyController.class);
    	
      protected ModelAndView onSubmit(Object formBackingObject) throws Exception {
        Map<String, Object> model = new HashMap<String, Object>();
        return new ModelAndView(this.getSuccessView(), model);
      }
    
      protected Object formBackingObject(HttpServletRequest request) throws Exception {
        LOGGER.info("[FORM BACKING OBJECT]");
        List <Item> selectedItems = ItemRepository.getSomeItems();
        return selectedItems;
      }
    
      protected Map<String,List<Item>> referenceData(HttpServletRequest request) throws Exception {
        LOGGER.info("[REFERENCE DATA]");
        Map<String,List<Item>> model = new HashMap<String,List<Item>>();
        List<Item> allItems = ItemRepository.geAllItems();
        model.put("allItems", allItems);
        return model;
      }
    	
      public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
        LOGGER.info("[HANDLE REQUEST INTERNAL]");
        Map<String, Object> model = new HashMap<String, Object>();
        return new ModelAndView(this.getFormView(), model);
      }
    
    }
    The logger is never called and in my JSPs no data is being received for the form.

    This is part of my formView jsp:
    Code:
    <spring-form:form>
      <spring-form:checkboxes path="selectedItems" items="${allItems}"/>
    </spring-form:form>
    BTW: I assume the path is wrong, but the methods above should be called although.

  • #2
    It is because you override the handleRequestInternal method screwing up the normal path of execution for the SimpleFormController. So either call super.handleRequestInteral or don't override it.

    Comment


    • #3
      Thank you! Problem solved.

      Comment

      Working...
      X