Announcement Announcement Module
Collapse
No announcement yet.
CancellableFormController equivalent with spring 3 annotation. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • CancellableFormController equivalent with spring 3 annotation.

    Hi all
    I have tried to use same functionality which was provided by CancellableFormController i.e. suppress validation of form with new spring 3 annotations but unfortunately could not find the way to do this.

    Please let me know if anybody has found a way to solve it.

  • #2
    annotated controllers are very different. If you want to suppress binding, simply dont ask for your model attribute in your method signature.

    1) public String doSave(@ModelAttribute("command") Foo command) //this will bind of course
    1) public String doSave() //this will not bind, no form object!

    Comment


    • #3
      Thanks for feedback

      Hi thanks the things which you have described I know but let's describe the problem which I am trying to solve so that you get from where is coming my question.

      I have wizard form with it controller which have known "next", "prev", "cancel" buttons and in controller I have one method which handles post requests and distinguish "next", "prev" or "cancel" actions by corresponding request param existence e.g. if "cancel" request paremetr exists in request then action is "cancel". Here is snapshot from method. So my question is how can I skip PatientRegistrationInfo object binding only when "_cancel" parameter exists in request?

      Code:
       @RequestMapping(method = RequestMethod.POST)
          public String submitForm(
                  HttpServletRequest request, HttpServletResponse response,
                  @ModelAttribute("patientRegistrationInfo") @Valid PatientRegistrationInfo patientRegistrationInfo,
                  BindingResult result, SessionStatus status,
                  @RequestParam("_page") int currentPage, Model model
          ) throws IOException {
              
                  if (request.getParameter("_cancel") != null) {
                      /// cancel ....
                  } else {
                      ......
                  }
             
          }

      Comment


      • #4
        Have you looked into @RequestMapping (params ="cancel=true" ) and (params ="cancel!=true" ) - you can do this with 2 handlers: one that maps to cancelled form, should not have PatientRegistrationInfo object binding


        @RequestMapping(method = RequestMethod.POST, params ="cancel=true" ) submitForm(
        HttpServletRequest request, HttpServletResponse response,
        BindingResult result, SessionStatus status,
        @RequestParam("_page") int currentPage, Model model
        ) throws IOException {


        // here you do not bind forma object - this handler will take over only when form is cancelled
        }

        @RequestMapping(method = RequestMethod.POST, params="cancel!=true" )
        public String submitForm(
        HttpServletRequest request, HttpServletResponse response,
        @ModelAttribute("patientRegistrationInfo") @Valid PatientRegistrationInfo patientRegistrationInfo,
        BindingResult result, SessionStatus status,
        @RequestParam("_page") int currentPage, Model model
        ) throws IOException {


        // for the rest of calls

        }



        google for documentation and code samples for more details

        Comment

        Working...
        X