Skip to content

Integrate RedirectAttributes with ModelMap [SPR-9418] #14054

@spring-projects-issues

Description

@spring-projects-issues

marc schipperheyn opened SPR-9418 and commented

I have been playing around with RedirectAttributes and although I like the FlashAttribute function, I don't really like the way it has been implemented.
For me, FlashAttributes come into play in the GET/POST/Redirect/displayStatus chain. What I don't like is that FlashAttributes aren't a transparent part of the ModelMap but instead separated through RedirectAttributes. I would prefer to say

model.addFlashAttribute(...) in stead of having the specify RedirectAttributes separately redirectAttributes.addFlashAttribute(...).

Also, when I add a FlashAttribute to a Model/RedirectAttributes and I don't redirect, I expect the FlashAttribute to be treated as a normal model attribute. and because they are separate, it isn't.

In the flow of a Controller, whether one redirects often depends on the context. And because RedirectAttributes are separate from ModelAttributes (when they are conceptually the same), I find myself having to duplicate certain actions, which is exactly what I want to avoid.

if(!member.isActive()){
   redirectAttributes.addFlashAttribute("status","Denied",RequestUtils.getLocale(request)));
   model.addAttribute("status","Denied",RequestUtils.getLocale(request)));
}

if(group.isHiddenToNonMembers()){
   return "empty";
}else{
   return "redirect:" + URLUtils.getGroupUrl(group, request);
}

What I would expect is to have a single action against the ModelMap
model.addFlashAttribute(...)
if the controller redirects, it is treated as a flash attribute
if the controller doesn't redirect, it treated as a model attribute


No further details from SPR-9418

Metadata

Metadata

Assignees

Labels

status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions