I have read the following topic:
Spring RedirectAttributes: addAttribute vs addFlashAttribute
As I understand it, the main difference between a flash attribute and a plain attribute is that a plain attribute can save only String
s and primitives.
But in practice I see another difference:
I have the following controller method:
....
redirectAttributes.addAttribute("error", messageSource.getMessage("AdminController.negativeSum", null, Locale.forLanguageTag("ru-RU")));
return "redirect:/admin/confirmWithdrawRequest";
and
@RequestMapping(value = "admin/confirmWithdrawRequest", method = RequestMethod.GET)
public String confirmWithdrawRequestShowPage(Model model) {
Set<Event> cashOutEvents = eventJournalService.getEventsByType(EventType.CASHOUT_REQUEST);
model.addAttribute("events", cashOutEvents);
model.addAttribute("statuses", EventStatus.values());
return "admin/confirmWithdrawRequest";
}
on the page confirmWithdrawRequest.jsp
I wrote the following code fragment:
<c:choose>
<c:when test="${not empty error}">
<div class="errorblock">
${error}
</div>
</c:when>
</c:choose>
Now I don't see the error message on my page.
If I replace redirectAttributes.addAttribute
with redirectAttributes.addFlashAttribute
- the error message will be shown.
Please explain this behaviour and show a scenario when I should use the addAttribute method.