Example usage for org.springframework.web.servlet.mvc.support RedirectAttributes containsAttribute

List of usage examples for org.springframework.web.servlet.mvc.support RedirectAttributes containsAttribute

Introduction

In this page you can find the example usage for org.springframework.web.servlet.mvc.support RedirectAttributes containsAttribute.

Prototype

boolean containsAttribute(String attributeName);

Source Link

Document

Does this model contain an attribute of the given name?

Usage

From source file:info.rmapproject.webapp.controllers.SearchController.java

/**
 * GETs the search form./* w  w w . ja  va 2s  . co  m*/
 *
 * @param model the Spring model
 * @param redirectAttributes holds flash attributes passed from a redirect
 * @return the search page
 */
@RequestMapping(method = RequestMethod.GET)
public String searchForm(Model model, RedirectAttributes redirectAttributes) {
    logger.info("Search page");

    if (redirectAttributes.containsAttribute("search")) {
        //true if redirected back to form due to error, for example.
        model.addAttribute("search", redirectAttributes.getFlashAttributes().get("search"));
        model.addAttribute("notice", redirectAttributes.getFlashAttributes().get("notice"));
    } else {
        //otherwise initiate search command.
        SearchCommand search = new SearchCommand();
        model.addAttribute("search", search);
    }
    return "search";
}