Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: SimpleFormController Issues

  1. #1
    Join Date
    Dec 2008
    Posts
    6

    Default 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.
    Attached Files Attached Files

  2. #2

    Default

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

  3. #3
    Join Date
    Dec 2008
    Posts
    6

    Default

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

  4. #4
    Join Date
    Dec 2006
    Posts
    311

    Default

    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).

  5. #5
    Join Date
    Dec 2008
    Posts
    6

    Default

    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.

  6. #6
    Join Date
    Dec 2006
    Posts
    311

    Default

    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.

  7. #7
    Join Date
    May 2008
    Location
    Central Florida, U.S.A.
    Posts
    36

    Default

    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?

  8. #8
    Join Date
    Dec 2008
    Posts
    6

    Default

    @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.

  9. #9
    Join Date
    Dec 2008
    Posts
    6

    Default

    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.

  10. #10
    Join Date
    Dec 2006
    Posts
    311

    Default

    FBO = formBackingObject.

Posting Permissions

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