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

  • Nested Forms


    I have a form process that extends AbstractWizardFormController. But while processing things within the wizard form, I want to put a link to start off different form process (may be a simpleform or wizardform).

    For an example, I have a customer wizard form. And while a user is stepping thru entering info on the Customer paneles, I want to have a link to start address wizard form that will allow to create address book entry (and suppose Customer does not have Address as a part of Customer command object).

    What I would like to know is, suppose I have above implementation, how could I come back to customer wizard form when the address form submission is completed successfully?

    What is the proper way to handle those situation?

    Thank you!!

  • #2
    I can think of a couple of different solutions; most revolve around saving state somewhere; and coding the other form to have a "returnTo" parameter.

    While session timeouts and server load might become a concern you could always just put the wizard contents into a session attribute so you can get them back.

    You might be able to either breakup the wizard transaction into pre/post states; or simply add some means (like an extra DB) table to store the incomplete state - then when/if the user returns to the wizard flow you can restore the state from server-side, even if the user's session timed out - depending on the amount of information and its sensitivity you could also store it as a cookie in the user's browser.

    As for the work flow - I haven't had time recently to look at any of the web navigation flow libraries; but you will obviously need some way to tell the "Add Address" page what to return/forward to apon completion. I'd tend to use a simple "returnTo" parameter (with wizard object's information as a query-string parameter) to tell the address controller what to do when completing (with a sensible default like the main page). This brings up an interesting point that I've seen a couple of times before, but have never found a solution that I really like - maybe someone knows a navigation flow library that helps out with managing this?


    • #3
      Webflow is not an easy thing to handle with spring, there is an open source project which I think does the job well, it is the springwebflow but I did not try to use it.

      From my own experience, and I used only the AstractWizardFormController, if you want to leave the wizard and forward to another controller, you can have a hidden field named _finish that you enabled by javascript, and a field named nextController which will tell which controller you want to forward to. After posting, it will execute the processFinish method of your wizard. With correct parameters in the request, your can forward to the next controller, after persisting your data.
      To come back to your Customer Workflow, you will have to have parameters in your request to tell which page you want to come back to on your controller. This parameter will be decoded in the method getInitalPage that you will override to display the correct page.

      Exemple :
      to leave your customer wizard to go to your address wizard :

      processFinish(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)  {
                  String nextController = request.getParameter("myNextController"); 
                  if (nextController!=null && "address".equals(nextController)) {
                      return new ModelAndView(new RedirectView("myAddressController.html");
      return new ModelAndView ("myFinishViewCustomer.html");
      to come back to the 2nd page of your abstract wizard controller Customer, after having inputed the address, you could do something like that after forwarding to MyCustomerWizardController.html?address=complete.

      protected getInitialPage(HttpServletRequest request) {
           String address = request.getParameter("address"); 
           if (address!=null && "complete".equals(address) {
                     return 2; 
           return super.getInitialPage(request);

      Hope this will help



      • #4
        As olivier points out the springwebflow controller can handle this kind of situation elegantly. You can find it at Read the practical guide to get started.