Results 1 to 3 of 3

Thread: Update single form on a multiform page

  1. #1
    Join Date
    Nov 2008
    Posts
    18

    Default Update single form on a multiform page

    Hi everybody,

    I have a main page that has multiforms.
    Each form is page for it self.
    It look something like this
    MainPage.vm consists of page1.vm, page2.vm, ...etc
    Main page has it own chainController
    Page1.vm is a form that has its own controller page1Controller.
    Page2.vm is a form that has its own controller page2Controller
    .
    .
    .
    All the controllers are chained in the chainedController for the main page!
    Every page/form has an update and a cancel button.

    Now, When a user change some data on page1/form1 and click on the update button for form1/pag1 the information is updated on the backend correctly, and before the page/form is displayed the referenceData is called, and it will make a GET-call to the backend to get the latest/updated information to display it.
    Now, my problem is, if the formView in the dispatcher-servlet.xml for page1Controller is set up as page1.vm only that page is displyed with the latest information, and if it is setup as Mainpage.vm it is displayed correctly, but all the other pages (page2, page3, ...etc) are empty.
    How can I display page1/form1 back in the mainpage without effecting the other pages content.
    Alternativly, How can I call the chainController on the mainpage again, so that it loops through all controllers for all the pages, and get all the information all over again?

    I'll be grateful if somebode can help me with som suggestions?

    Regards
    Azam

  2. #2
    Join Date
    Dec 2008
    Location
    Brussels, Bucharest
    Posts
    3

    Default Update single form on a multiform page

    I use one controller for all the forms I may have in a page.
    Every form has a hidden element name="formBeanName".
    In setupForm method(described below), I add all formBeans to session(I know when to do cleanup) (@SessionAttributes is not for this).
    See processSubmit method, described below.

    @Controller
    @RequestMapping("/getttr.htm")
    @SessionAttributes( { "getttr", "tertmt", "getter", "terset" })
    public class GetttrFormController {

    @RequestMapping(method = RequestMethod.POST)
    public String processSubmit(@RequestParam("formBeanName") String formBeanName,
    @ModelAttribute("getter") GetterForm getter,
    @ModelAttribute("terset") TersetForm terset,
    @ModelAttribute("tertmt") TertmtForm tertmt,
    @ModelAttribute("getttr") GetttrForm getttr, BindingResult result, Model model,
    HttpServletRequest request, HttpSession session)
    {
    FormBean formbean = (FormBean) model.asMap().get( formBeanName.toLowerCase() );

    ... }

    @RequestMapping(method = RequestMethod.GET)
    public String setupForm(Model model, HttpServletRequest request)
    {
    ..//add your formBeans to session

    }

    }//end class

  3. #3
    Join Date
    Dec 2008
    Location
    Brussels, Bucharest
    Posts
    3

    Default Update single form on a multiform page - Validator

    You should take special care for the validation phase:

    let's say you have this method:
    @RequestMapping(method = RequestMethod.POST)
    public String processSubmit(@RequestParam("formBeanName") String formBeanName,
    @ModelAttribute("getter") GetterForm getter,
    @ModelAttribute("terset") TersetForm terset,
    @ModelAttribute("tertmt") TertmtForm tertmt,
    @ModelAttribute("getttr") GetttrForm getttr, BindingResult result, Model model,
    HttpServletRequest request, HttpSession session)
    {
    FormBean formbean = (FormBean) model.asMap().get(
    formBeanName.toLowerCase() );
    target = formbean ;
    result = new BeanPropertyBindingResult( target, objectName);
    ValidationUtils.invokeValidator( yourValidatorForTheSelectedBean, formbean, result );

    //formBeanName = hidden elm in every form from the composite page.

Posting Permissions

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