Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
1.5k views
in Programming by
retagged by
I have a controller where I do validation of a value I am receiving from the form. Next thing we need is to redirect to new page. But I need to keep values from previous page. How do I achieve this?

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
You can resolve it by using org.springframework.web.servlet.mvc.support.RedirectAttributes.

 

Here is my controller sample.

 

@RequestMapping(method = RequestMethod.POST)
    public String eligibilityPost(
            @ModelAttribute("form") @Valid EligibiltyForm form,
            Model model,
            RedirectAttributes redirectAttributes) {
        if(eligibilityService.validateEligibility(form)){
            redirectAttributes.addFlashAttribute("form", form);
            return "redirect:<redirect to your page>";
        }
       return "eligibility";
    }

 

In above I used redirectAttributes.addFlashAttribute("form", form);

 

Now in get controller I can utilize it this way.

This is get controller for your page

@RequestMapping(method = RequestMethod.GET)
    public String getListUsersView(@ModelAttribute("form") @Valid EligibiltyForm form,
            Model model) {
        model.addAttribute("number", form.getNumber());
        return "paymentandshipping";
    }

 

Let us know if that helps.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...