Announcement Announcement Module
No announcement yet.
onSubmit - Say it ain't so Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • onSubmit - Say it ain't so

    I am trying to implement the File Upload code example on page 138 (Version 1.2 RC2) of the reference documentation and have noticed that although the successview is reached after I submit the form, nothing within the onSubmit() method is processed. That is, no logger info is written and the file is not saved. How is this possible? I thought that if the successview is reached, the onSubmit() method must have been called. Since this is not happening, how can the successview be reached? How can it be skipped? Is it a configuration issue?

    I have another form that also exhibits this behavior, so I placed my processing code within the Validator, but am curious what could be causing the SimpleFormController to behave this way.

    I am using Spring 1.2RC2, and Tomcat 5.0.18, and lib files from the Spring distribution.

  • #2
    There are three overloaded versions of onSubmit. By default the version with the full parameter set calls a simpler one, which in turn calls the simplest one. Which one are you expecting to be called?

    Also sometimes it might be your overriding version isn't really overriding (e.g. mismatching signatures).


    • #3
      I am using the one from the example. That is,

      protected ModelAndView onSubmit(
      HttpServletRequest request,
      HttpServletResponse response,
      Object command,
      BindException errors)
      throws ServletException, IOException { }

      The fact that the calls from within this method are not reached and yet a successview is returned is somewhat troubling. So how is it possible that a view is returned without the business logic being invoked? Again, this example is taken directly from the reference docs. I would be happy to send the war file to anyone who wants to observe the behavior.


      • #4
        That is strange. Are any of the methods being invoked in your form controller. You could try overriding for example the formBackingObject or showForm methods to ensure your controller is being used for the post?


        • #5
          Make sure your method is actually overriding the superclass method. That bit one of my team just today.


          • #6
            None of the methods within the onSubmit are being invoked. The FormController is initialized but when the form is submitted only the view wired in the application context file is returned. If I need to invoke business logic I am forced to place it in the Validator. Although I am not opposed to this solution, the framework is not behaving as expected and thus I am concerned.

            rstearns01 - Could you elaborate a little more. How do I make sure the onSubmit is actually overriding the sperclass method, since this is essentially the problem. What could be missing that allows the successview to be returned, but does not perform any methods contained within the onSubmit()?

            Since it is apparent that a successview can be returned without any methods within the onSubmit() being invoked, another way of putting this issue is, what needs to be done to guarantee the correct behavior?



            • #7
              I think what Randy means is check that the signature of your overriden method is exactly right...I too have spent many an unhappy hour trying to work out why overriden methods were not getting invoked - I now make sure to let my IDE (eclipse) generate method sigs for me (Ctrl-Space) !



              • #8
                Originally posted by fineman
                I think what Randy means is check that the signature of your overriden method is exactly right
                Precisely. Even if you copy/paste from somewhere else, you're not guaranteed it will override; especially if your class has already imported a class with the same name as in your signature, but a different package.

                Check your IDE (normally the right gutter). There should be a small icon informing you that the method is an override. If not, have your IDE generate it. If it is, double check your handler mapping is referencing the controller you think it is.



                • #9
                  Thanks to everyone who responded to my problem.

                  I went back to the API (RTFM) and discovered you were all correct. I had the response and request order reversed in the onSubmit(). I, as well, will have to create some eclipse templates to be sure to avoid this in the future.

                  I sure appreciate your responses.