Results 1 to 6 of 6

Thread: No way to cancel in SimpleFormController

  1. #1

    Default No way to cancel in SimpleFormController

    How do you allow a user to cancel a form submission that has errors and fails validation? Some solutions that were suggested in an earlier post:

    1. Override suppressValidation. However, since it's final and can't be overriden, I suspect nobody actually tried this. In any case, it only affects the validation not the workflow. There's still no way to capture the user's action and bail out of the form.

    2. Separate form for the cancel button using a GET and a different ACTION. This works, but precludes the use of a generic button bar because the cancel ACTION is hardcoded.

    3. Use Javascript to achieve the same effect as #2. Work great as long as the browser has Javascript and it's turned on, neither of which you have any control over.

    All of the above soutions are pretty hacky, IMHO. The root issue is that the idea of cancelling a form submission isn't part of the workflow. Granted, HTML is brain-dead that way. Traditional forms have submit and reset, but the only way to bail is to have alternate links. My own hack is to derive from AbstractWizardFormController instead where the cancel action is explicitly trapped for.

    Anyone have a clean solution to the problem? I may eventually create an alternate SimpleFormController that traps for cancel, but doesn't bring in all the rest of the Wizard machinery.

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    You can override processFormSubmission as follows:
    Code:
      public ModelAndView processFormSubmission(HttpServletRequest request,
                                                HttpServletResponse response,
                                                Object command,
                                                BindException errors) throws Exception {
        String action = request.getParameter(Globals.CANCEL);
    
        if (Globals.CANCEL.equalsIgnoreCase(action)) {
          return new ModelAndView("cancel");
        }
    
        return super.processFormSubmission(request, response, command, errors);
      }
    Globals is a constants class.
    HTH
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3

    Default

    And it was even right there in the documentation waiting for me, with this issue as the example use case. Duh. Thanks for the pointer.

  4. #4

    Default

    However, it does have the drawback of doing a lot of unnecessary work in the case of a cancel. That was the original poster's objection in the other thread I mentioned. I've looked at the doc and source, but so far haven't figured out a way to bail from processing and redirect to another page before binding and vaildation. Not the end of the world, but would be cleaner to find a way to do this.

  5. #5
    Join Date
    Jan 2006
    Posts
    1

    Default

    Quote Originally Posted by pearsons_11114
    However, it does have the drawback of doing a lot of unnecessary work in the case of a cancel. That was the original poster's objection in the other thread I mentioned. I've looked at the doc and source, but so far haven't figured out a way to bail from processing and redirect to another page before binding and vaildation. Not the end of the world, but would be cleaner to find a way to do this.
    I'm new at this. I just ran into the same issue. For example: if the user changes his/her mind on editting the data. Seems a 'cancel' should be part of the form controller and all I would have to do is supply were to go on the cancel. Well I supplied a button (the dirty way):
    <input name="cancel" type="submit" class="button" value=" Cancel " onclick="javascript:window.location.href=/wheretheyneedtogo.htm">

    Or I could just expect them to use the 'Back Button'.

  6. #6
    Join Date
    Aug 2004
    Location
    Whitehorse, YT, Canada
    Posts
    26

    Default

    Instead of subclassing SimpleFormController, just subclass CancellableFormController and override one of the onCancel methods or just set cancel view with the "setCancelView" method. This class subclasses SimpleFormController, so you won't have to change anything else in your class. If you're using session forms, this has the benefit of removing your form from the session.

    smv
    Last edited by smv; Mar 1st, 2006 at 07:11 PM.

Similar Threads

  1. SimpleFormController not do onSubmit
    By heleno_alves in forum Web
    Replies: 2
    Last Post: Oct 18th, 2005, 07:22 AM
  2. popup menu. escape key, and cancel command
    By lstreepy in forum Swing
    Replies: 3
    Last Post: Sep 13th, 2005, 11:45 AM
  3. SimpleFormController Issue
    By zrawley in forum Web
    Replies: 14
    Last Post: Jul 31st, 2005, 07:27 AM
  4. Replies: 5
    Last Post: Dec 16th, 2004, 11:47 AM
  5. Servlet & portlet packages (SimpleFormController)
    By mpetrashev in forum Architecture
    Replies: 0
    Last Post: Dec 2nd, 2004, 10:11 AM

Posting Permissions

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