spring-webmvc

org.springframework.web.servlet.mvc.support
Interface RedirectAttributes

All Superinterfaces:
org.springframework.ui.Model
All Known Implementing Classes:
RedirectAttributesModelMap

public interface RedirectAttributes
extends org.springframework.ui.Model

A specialization of the Model interface that controllers can use to select attributes for a redirect scenario. Since the intent of adding redirect attributes is very explicit -- i.e. to be used for a redirect URL, attribute values may be formatted as Strings and stored that way to make them eligible to be appended to the query string or expanded as URI variables in org.springframework.web.servlet.view.RedirectView.

This interface also provides a way to add flash attributes. For a general overview of flash attributes see FlashMap. You can use RedirectAttributes to store flash attributes and they will be automatically propagated to the "output" FlashMap of the current request.

Example usage in an @Controller:

 @RequestMapping(value = "/accounts", method = RequestMethod.POST)
 public String handle(Account account, BindingResult result, RedirectAttributes redirectAttrs) {
   if (result.hasErrors()) {
     return "accounts/new";
   }
   // Save account ...
   redirectAttrs.addAttribute("id", account.getId()).addFlashAttribute("message", "Account created!");
   return "redirect:/accounts/{id}";
 }
 

A RedirectAttributes model is empty when the method is called and is never used unless the method returns a redirect view name or a RedirectView.

After the redirect, flash attributes are automatically added to the model of the controller that serves the target URL.

Since:
3.1
Author:
Rossen Stoyanchev

Method Summary
 RedirectAttributes addAllAttributes(java.util.Collection<?> attributeValues)
           
 RedirectAttributes addAttribute(java.lang.Object attributeValue)
           
 RedirectAttributes addAttribute(java.lang.String attributeName, java.lang.Object attributeValue)
           
 RedirectAttributes addFlashAttribute(java.lang.Object attributeValue)
          Add the given flash storage using a generated name.
 RedirectAttributes addFlashAttribute(java.lang.String attributeName, java.lang.Object attributeValue)
          Add the given flash attribute.
 java.util.Map<java.lang.String,?> getFlashAttributes()
          Return the attributes candidate for flash storage or an empty Map.
 RedirectAttributes mergeAttributes(java.util.Map<java.lang.String,?> attributes)
           
 
Methods inherited from interface org.springframework.ui.Model
addAllAttributes, asMap, containsAttribute
 

Method Detail

addAttribute

RedirectAttributes addAttribute(java.lang.String attributeName,
                                java.lang.Object attributeValue)
Specified by:
addAttribute in interface org.springframework.ui.Model

addAttribute

RedirectAttributes addAttribute(java.lang.Object attributeValue)
Specified by:
addAttribute in interface org.springframework.ui.Model

addAllAttributes

RedirectAttributes addAllAttributes(java.util.Collection<?> attributeValues)
Specified by:
addAllAttributes in interface org.springframework.ui.Model

mergeAttributes

RedirectAttributes mergeAttributes(java.util.Map<java.lang.String,?> attributes)
Specified by:
mergeAttributes in interface org.springframework.ui.Model

addFlashAttribute

RedirectAttributes addFlashAttribute(java.lang.String attributeName,
                                     java.lang.Object attributeValue)
Add the given flash attribute.

Parameters:
attributeName - the attribute name; never null
attributeValue - the attribute value; may be null

addFlashAttribute

RedirectAttributes addFlashAttribute(java.lang.Object attributeValue)
Add the given flash storage using a generated name.

Parameters:
attributeValue - the flash attribute value; never null

getFlashAttributes

java.util.Map<java.lang.String,?> getFlashAttributes()
Return the attributes candidate for flash storage or an empty Map.


spring-webmvc