Announcement Announcement Module
Collapse
No announcement yet.
spring 3.0 mvc multi page form Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring 3.0 mvc multi page form

    How do you implement a multi page form in spring 3.0

    I am attempting to employ spring 3.0 with jsp.

    I would like to use one controller using @Controller annotation and have multiple jsps process an idividuals personel details, such and Name, Age, medical details, education, etc.

    is this possible ?

    Is this a "wise choice"?

    Do I need to also use Spring Web Flow?

    I have spent the last four days Googling and searching/reading books and reference documents.

    Cheers

    Dick Dastardly

  • #2
    How about to have one form controller per form and redirect to the next form controller once the current controller is submitted properly?

    Comment


    • #3
      Im facing a similar issue. My application has around 4 to 5 individual journeys/flows each of which consist of a sequence of 3-4 pages. Im trying to implement these flows using spring 3.0 annotated controllers. I was able to implement a single flow in a wizard like fashion, however the problem im faced with now is how to protect the integrity of each flow i.e. ensure that the flow is always initiated from the starting view (page #1) and the user is not able to type in the URL and jump directly into say page #2 or #3. Currently looking up some out of the box feature in spring that I can use for this. Any ideas anyone?

      If not then it seems like i`ll have to invest some time looking at Web Flow or come up with custom logic to implement navigation rules per flow (dont wanna go down that route).

      Suggestions?
      Last edited by zzkhan; Jan 11th, 2010, 08:59 PM.

      Comment


      • #4
        To vw729: Thanks for your suggestion... However I thought the whole idea of a multi page form was to have a single controller with a number of related pages. This makes completion of a domain object easier and held in one place.

        To zzKhan: while i was testing my attempts at multi page forms it I was trying to keep the url unchanged but navigate from one page to another. i.e. do not use redirect:'s but either simply a new logical view name or forward:'s.
        have you thought of url re writing with http://tuckey.org/urlrewrite/ ?

        Comment


        • #5
          Originally posted by zzkhan View Post
          ...I Currently looking up some out of the box feature in spring that I can use for this. Any ideas anyone?
          Suggestions?
          If you don't want to use the Spring webflow, currently, there is not an out of the box solution. However, there is a future solution in the next Spring release: conversation management. I was told a three months time frame if you can wait.

          Comment


          • #6
            Originally posted by dastardly View Post
            To vw729: Thanks for your suggestion... However I thought the whole idea of a multi page form was to have a single controller with a number of related pages. This makes completion of a domain object easier and held in one place.
            ...
            If you don't mind using the will-be-deprecated controller, you can find an inheritance based controller to meet your need. (I can't recall its name at this moment)

            Comment


            • #7
              I've replaced my old wizard forms that inherited from AbstractWizardFormController with annotated controllers.

              The multi-page functionality can be achieved using one method that returns different views depending on the state of the model object. This is very simplified, but the basic idea is something like this:

              Code:
              @RequestMapping(method = RequestMethod.POST)
              public ModelAndView processSubmit(
              @ModelAttribute("pet") Pet pet,
              SessionStatus status) {
              	if (pet.getFieldOne() == null) {
              		//return the form that will set field one's value
              		return new ModelAndView( ... );
              	} else if (pet.getFieldTwo() == null) {
              		//return the form that will set field two's value
              		return new ModelAndView( ... );
              	} //and so on for all the other field that need to be set...
              	...
              	else {
              		//once the object has all necessary fields
              		//set and validated, then do what needs
              		//to be done to finish. Store object, end
              		//session, and return your success view.
              		this.clinic.storePet(pet);
              		status.setComplete();
              		return new ModelAndView( ... );
              	}
              }
              You'll need to make sure that your model object is included in @SessionAttributes for the controller. Also, you'll probably want some validation.

              Comment


              • #8
                uaine



                nice idea, that approach had not occurred to me, I'll give it a go...

                also i'll attempt to design a clean way of detecting the current page being POSTed

                thanks for bothering to look at this

                Cheers

                DD

                Comment


                • #9
                  Hi!

                  I'm currently trying to create a form wizard involving 3 steps in a Spring MVC application. My idea is also to use a single controller for the whole process but it's difficult for me to understand how to go about this. I find the concept of @SessionAttributes to be very confusing and redirects doesn't seem to be working at all for navigating between forms (The url-field in the browser isn't updated.) Can I have more than one SessionAttribute for one controller and how do they work? I've been trying to understand their use in the PetClinic sample but I can't really say that I'm any wiser (Especially since removing any reference to a SessionAttribute from the AddPetForm-controller doesn't seem to change its behaviour to any noticeable degree?) I don't really want to start messing around with webflows at this stage for the kind of simple application I'm making.

                  I'd appreciate any suggestions.

                  /Kris

                  Comment


                  • #10
                    You can have multiple sessionattributes in a single controller


                    you specify them like this

                    @SessionAttributes( {"attrOne", "attrTwo"})


                    I would steer clear of redirects

                    Try this

                    for each page have a button with an href for the page you are on
                    such as /next/pageOne

                    or /next/pageTwo

                    then match this against the controller method you want to process that page
                    I think (although its possibly confusing) its the best idea to make the /next/pageXXX refer to the current page being processed this was you dont have to keep a link between the actual page sequence.

                    I hope that makes some sort of sense and also helps you a bit!

                    Comment


                    • #11
                      20/20 hindsight

                      @dastardly and @uaine:
                      given what you know now, is this the best approach for solving the 'I need a wizard, but I'm using a @Controller' issue?

                      The multi-page functionality can be achieved using one method that returns different views depending on the state of the model object. This is very simplified, but the basic idea is something like this:
                      @dastardly:

                      also i'll attempt to design a clean way of detecting the current page being POSTed
                      were you successful in finding a clever way to detect current page? could you post a simple example?

                      thanks!

                      Comment


                      • #12
                        I have used Abstart WizardForm Controller in my Spring 2.5 MVC application.I migrtaed to Spring 3 .AbstratctWizardForm Controller is deprecated one, i need to replace this wizardFormcontroller in my application..?any idea?Just send me related codes here..i will see..

                        Comment


                        • #13
                          Wizard Controller functionality with Spring

                          I have multiple workflows with variable number of pages in each workflow.
                          Data as well as controls info of each page is coming from DB.

                          So pages have to created and filled with data (if any existing) at run-time depending on workflow selected and page one is on currently. I have limited experience on Java let alone Spring. This will be a web app. As I understand this has to use Spring. Any help/pointers on whether i should go with single controller with multiple pages/ multiple controllers and how Spring could be helpful as a framework, are welcome...

                          Thanks.

                          Comment

                          Working...
                          X