How do I redirect to another controller with a path variable in the redirect. I tried it the following way but get this error:
java.lang.IllegalArgumentException: Model has no value for key 'formId'
How I implemented it:
Long formId = drugType.getFormId();
view = "redirect:/pub/req/customForm/view/{formId}";
And received by the controller:
@RequestMapping(method = RequestMethod.POST, value = "/pub/req/customForm/view/{formId}")
String completeCustomForm(@PathVariable Long formId,
@Valid @ModelAttribute CustomFormLayout customFormLayout,
BindingResult errors, HttpServletRequest request, Model model,
RedirectAttributes attr) {
Any ideas how I can redirect to this controller with the formId value?
You could either build the redirect address string:
return "redirect:/pub/req/customForm/view/" + drugType.getFormId();
Or add a model attribute named as your path variable ("formId
") and use it in your view name (this is what the error message is telling you)
model.addAttribute("formId", drugType.getFormId());
return "redirect:/pub/req/customForm/view/{formId}";
Try applying the parameter:
Long formId = drugType.getFormId();
view = "redirect:/pub/req/customForm/view/"+formId;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With