Welcome to the Question and Answer site for Software Testing Professionals

You can get your queries resolved from Software Testing Professionals.

Ask a Question

Get answers and give answers to questions from other members.

View All Questions

Get votes and earn points to build your reputation in community.

View Hot Questions

0
how do I redirect to page keeping model value?

Open 1 Answers 753 Views Programming
0 1
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
0
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.
answered May 10, 2016 by stbadmin (192 points)

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

We have resolved 1.2k+ Software Testing queries!

Software Testing Board Weekly update

We will send you handpicked questions that you would love to answer.

View previous campaigns.

Top Contributors

...