Announcement Announcement Module
Collapse
No announcement yet.
SimpleFormController Issues Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleFormController Issues

    Forgive me if this has been asked before, but I have googled, and searched this forum and have yet to find a solution to my problem.

    I have a form built off of the SimpleFormController. What I'd like is to have the form prepopulate, and then the user can either press the "next" button which does a javascript:document.mycommand.submit() OR they can click another button which also does document.mycommand.submit(), but also sets an form element called addNew to true. If this element is submitted with the value true, I'd like the controller to save the form command object to the database and then return a new blank form.

    I can get it to save to the database, but it will not load a new form. I've checked to make sure the element is being set. The only other thing I can think of is to override the SimpleFormController's isFormSubmission, but I've heard there are issue with that.

    The form also has an element that when set will load from the database a specific object based on id.

    Any advice is welcome. Code is attached.

  • #2
    Did you try setting the command obj to null once the data is saved successfully to db?

    Comment


    • #3
      I tried that and it didn't help, but thanks for the suggestion. It was one I hadn't actually gotten around to.

      Comment


      • #4
        I see that you do a redirect on form submission. Are you directing to a different page or is this the same page? I am thinking that you are loading the object again from the db once its saved. You would have to override isFormSubmission or modify your FBO to avoid that.

        Of course the easiest thing to do would be to redirect to a different page (like a summary page).

        Comment


        • #5
          Unfortunately redirecting to a summary page isn't an option, though I did think about redirecting to a forwarding page. What would be the best way to override isFormSubmission? I've read more than once this method tends to be more trouble than it's worth.

          Comment


          • #6
            Overriding it is simple. You just inspect the request for the submit button parameter that determines if its a submit and return true for those. For example:


            protected isFormSubmission(HttpServletRequest request){
            return (request.getParameter("save") != null);
            }

            This would say that anything with a save parameter is a form submission.


            As a test to make sure thats your problem do a test and return a new FBO at the end of that method so that you know your getting a clean object all the time. If that works then you know that is the behavior you will want so you can play around with that method until it works out.

            Comment


            • #7
              What exactly is it doing right now, instead of showing a new form? Because it appears you aren't returning to the page in the case of validation errors. I see the only time you show the form again is when a database save/update throws an exception. Otherwise you're performing a redirect. I can't see how your even attempting to re-render the page with a new form object. Can you elaborate a little more?

              Comment


              • #8
                @TermInMD
                I think I understand what you're suggesting, but what is an FBO?

                @mrcritical
                It's returning the form with the same command object (basically the form is prepopulated with the same info I just saved.) And it's also going straight to onFormSubmission and thus saving it twice. I was simply returning a model and view and if I set a different successView in my applicationContext file it will go to that properly, but I need it to return the form possibly empty, possibly prepopulated with a different object based on what the user clicks, or finally (if they're done) a different page altogether.

                Comment


                • #9
                  I should also add that most (if not all) of the validation is being done on the client-side via vanilla javascript and/or ajax.

                  Comment


                  • #10
                    FBO = formBackingObject.

                    Comment


                    • #11
                      @TerpInMD
                      I took your advice and overrode isFormSubmission as follows:
                      Code:
                      protected boolean isFormSubmission(HttpServletRequest request) {
                      		
                      		return (request.getParameter("next") != null);
                      	}
                      However, all I need now is to be able to still save the form even though it is technically NOT a "submission". I tried setting request.getParameter("add") to true AND request.getParameter("next") to true, but that seems to skip onSubmit, which is the only place I'm saving the form. Should I be adding a clause for (if add.equals("true")) save existing form and return a new on in the FBO method?

                      Thanks for your help.

                      Comment

                      Working...
                      X