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

  • formBackingObject not getting called

    Hi Folks,

    I have a jsp page with links that map to my controller that extends SimpleFormController. The links have a query string at the end to indicate an id in which I want my overridden formBackingObject to use to populate a form with. The problem is simply that my formBackingObject method is not being called. I'm using a SimpleFormController controller in my login page as well and when I browse to this page the formBackingObject is called there. But for some reason this controller that I want to populate a form with is not getting the formBackingObject called. Any ideas would be greatly appreciated.

    Thanks.

  • #2
    Hi Guys,

    I might have figured this out, but it brings up more questions. In my handleRequestInternal() I was returning a new ModelAndView object that I was pointing to my form view. Because of this, it was preventing the formBackingObject from being called. I was under the assumption that formBackingObject would be called in all cases. Does this sound correct?

    Comment


    • #3
      SimpleFormController's workflow logic is implemented in its handleRequestInternal(..) method, and therefore you don't want to override that. The formBackingObject(..), initBinder(..), and referenceData(..) methods provide the 'hooks' for modifying the default behaviour. Occasionally - but rarely - it may be necessary to implement one of the showForm(..) methods. Can you briefly describe how you would like to modify or extend the default behaviour. If necessary, then feel free to include a code excerpt from your current handleRequestInternal(..) implementation.

      Comment


      • #4
        Hi Mark,

        Thanks for the info. This is what I'm doing in my handleRequestInternal method:

        Code:
        protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
        
        String action = request.getParameter("action");
              
              if("delete".equals(action)) {
                 
                 String id = request.getParameter("id");
                 albumService.deleteAlbum(id);
                 return new ModelAndView(getSuccessView());
                 
              }
              
              return super.handleRequestInternal(request, response);
        
        }
        As you can tell, I'm simply looking for a delete action and if found doing some backend stuff, then forwarding to another controller. Otherwise I have the parent do it's thing. Is it generally a bad idea to override handleRequestInternal? Are there plans to make it final? Thanks.

        Comment


        • #5
          It looks like you could implement this behaviour in an onSubmit(..) method instead if the "delete" action is populated in a form submission as opposed to an initial GET request.

          The default workflow regards a POST request as a form submission. However it is possible to override the isFormSubmission(..) method to check for the presence of an "action" parameter.

          That said, you may actually want to question the need for extending SimpleFormController in this case if you are not doing any binding or validation.

          Comment


          • #6
            The delete action will be coming off the query string of a url from my jsp page. My page is listing a collection of items, each with links to either view or delete them. If the action is to delete, I want that to happen in the controller (delegated to a service object), and the orginal view to be returned. If the action is to view, I want the formBackingObject to be called to pull the item's details from the db to be presented in a form. The reason I made this controller a subclass of SimpleFormController was because it then handles any edits performed on the page when the item is being viewed. This setup has been working nicely for me, but I am concerned that overriding handleRequestInternal may not be wise. I thought it would be ok since I'm delegating to its parent in all cases but one.

            Thanks.

            Comment


            • #7
              You might want to consider separating the "delete" and the "view" into 2 separate controllers. For the delete in particular, the SimpleFormController is probably overkill.

              Comment


              • #8
                Hi Mark,

                Thanks for the tip, this will remove the need to override the handleRequestInternal. Should the lesson to all of this be that a controller should only perform a single task? Thanks again.
                -Mike

                Comment


                • #9
                  I actually wouldn't say that 1 controller per task should be taken as a general rule. The MultiActionController can be very useful and efficient in handling related functionality for example. However, in the situation where 1 "action" requires the form workflow logic, and the other action is much simpler, then it might be better to keep them separate. Another valid option may be to put that conditional logic into the onSubmit(..) method for handling a form submission. It is partly a matter of taste but should always be considered for the use-case in question.

                  Comment


                  • #10
                    By the way, you really might want to have a look at AbstractCommandController as a base class instead of SimpleFormController. You can still take advantage of the "command" object and can override getCommand(..). Since you don't need to use the form workflow, this is probably a better fit.

                    Comment


                    • #11
                      overkill

                      Hello Mark Fisher

                      ===
                      You might want to consider separating the "delete" and the "view" into 2 separate controllers. For the delete in particular, the SimpleFormController is probably overkill.
                      ==

                      I am using a SimpleFormController for "delete". Could you please explain more above this. What kind of controller I should you so it is not "overkill"

                      Thanks
                      sho

                      Comment

                      Working...
                      X