Example usage for org.springframework.ui ModelMap addAttribute

List of usage examples for org.springframework.ui ModelMap addAttribute

Introduction

In this page you can find the example usage for org.springframework.ui ModelMap addAttribute.

Prototype

public ModelMap addAttribute(String attributeName, @Nullable Object attributeValue) 

Source Link

Document

Add the supplied attribute under the supplied name.

Usage

From source file:cn.hbu.cs.esearch.controller.EsearchController.java

@RequestMapping("_search")
public String search(@RequestParam String query, ModelMap modelMap) {

    modelMap.addAttribute("isSearchRequest", true);
    if (StringUtils.isEmpty(query)) {
        LOGGER.info("Query string is empty.");
        return "index";
    }//w ww  . java 2 s . c  o m
    if (Strings.isNullOrEmpty(query)) {
        return "index";
    }
    SearchRequest searchRequest = new SearchRequest(query);

    LOGGER.info("Query :{}", query);

    SearchResult searchResult = null;
    try {
        searchResult = searchService.search(searchRequest);
    } catch (EsearchException e) {
        LOGGER.error("Query failure, the error is: \n {}", e);
    }
    if (searchResult != null) {
        modelMap.addAttribute("totalTime", searchResult.getTime());
        modelMap.addAttribute("totalHits", searchResult.getTotalHits());
        modelMap.addAttribute("totalDocs", searchResult.getTotalDocs());
        modelMap.addAttribute("searchHits", searchResult.getHits());
    } else {
        modelMap.addAttribute("totalTime", 0);
        modelMap.addAttribute("totalHits", 0);
    }
    modelMap.addAttribute("query", query);
    return "index";
}

From source file:cz.muni.fi.mir.controllers.ConfigurationController.java

@Secured("ROLE_ADMINISTRATOR")
@RequestMapping(value = { "/create", "/create/" }, method = RequestMethod.POST)
@SiteTitle("{entity.configuration.create}")
public ModelAndView createConfigurationSubmit(
        @Valid @ModelAttribute("configurationForm") ConfigurationForm configurationForm, BindingResult result,
        Model model) {/*from w w w.j  a v  a  2 s . c o  m*/
    if (result.hasErrors()) {
        ModelMap mm = new ModelMap();
        mm.addAttribute("configurationForm", configurationForm);
        mm.addAttribute(model);

        return new ModelAndView("configuration_create", mm);
    } else {
        configurationService.createConfiguration(mapper.map(configurationForm, Configuration.class));

        return new ModelAndView("redirect:/configuration/list/");
    }
}

From source file:edu.mayo.cts2.uriresolver.controller.LoginController.java

@RequestMapping(value = "/public/loginfailed", method = RequestMethod.GET)
public String loginfailed(ModelMap model) {
    logger.info("loginfailed");

    model.addAttribute("loginFailed", "true");
    return "public/login";

    //return new ModelAndView("redirect:/");
}

From source file:com.stitchgalaxy.sg_manager_web.HomeController.java

@RequestMapping(value = { "", "/", UrlConstants.URL_HOME }, method = RequestMethod.GET)
public String home(ModelMap model) {

    List<ProductInfo> products = domainDataService.getAllProducts(new CommandGetProducts());
    model.addAttribute("products", products);
    UrlConstants.AddUrlConstants(model);

    return "home";
}

From source file:edu.ijse.tcd.controller.GradeController.java

@RequestMapping(value = "grade", method = RequestMethod.GET)
public String loadGrade(ModelMap map) {
    Grade grade = new Grade();
    ArrayList<Grade> grades = gradeService.getGrades();

    map.addAttribute("gradeMap", grade);
    map.addAttribute("gradeList", grades);
    return "grade";
}

From source file:eu.jasha.demo.sbtfragments.CityController.java

@RequestMapping
public String overview(ModelMap modelMap) {
    modelMap.addAttribute(MODEL_ATTRIBUTE_CITIES, cityDao.getAll());
    return VIEW_CITIES;
}

From source file:it.f2informatica.webapp.controller.NavBarController.java

@RequestMapping(value = "/home", method = RequestMethod.GET)
public String homePage(ModelMap model) {
    number++;/*from   ww w.  j a  v  a  2  s  .c  om*/
    System.out.println(number);
    model.addAttribute(SessionAttribute.NAVBAR_ITEM_ACTIVE, 0);
    return "homePage";
}

From source file:net.groupbuy.controller.shop.member.MemberController.java

/**
 * //from w w w  .  j  a  v a 2s  .co m
 */
@RequestMapping(value = "/index", method = RequestMethod.GET)
public String index(Integer pageNumber, ModelMap model) {
    Member member = memberService.getCurrent();
    model.addAttribute("waitingPaymentOrderCount", orderService.waitingPaymentCount(member));
    model.addAttribute("waitingShippingOrderCount", orderService.waitingShippingCount(member));
    model.addAttribute("messageCount", messageService.count(member, false));
    model.addAttribute("couponCodeCount", couponCodeService.count(null, member, null, false, false));
    model.addAttribute("favoriteCount", productService.count(member, null, null, null, null, null, null));
    model.addAttribute("productNotifyCount", productNotifyService.count(member, null, null, null));
    model.addAttribute("reviewCount", reviewService.count(member, null, null, null));
    model.addAttribute("consultationCount", consultationService.count(member, null, null));
    model.addAttribute("newOrders", orderService.findList(member, NEW_ORDER_COUNT, null, null));
    return "shop/member/index";
}

From source file:org.motechproject.server.omod.web.controller.CommunityController.java

@RequestMapping(value = "/module/motechmodule/community/add.form", method = RequestMethod.GET)
public String viewAddForm(ModelMap modelMap) {
    modelMap.addAttribute("community", new WebCommunity());
    return "/module/motechmodule/addcommunity";
}

From source file:org.obp.web.SimpleController.java

@RequestMapping("/simple/manifest")
public String manifest(ModelMap model) {
    model.addAttribute("realm", obp);
    return "simple/manifest";
}