Example usage for org.springframework.ui Model containsAttribute

List of usage examples for org.springframework.ui Model containsAttribute

Introduction

In this page you can find the example usage for org.springframework.ui Model containsAttribute.

Prototype

boolean containsAttribute(String attributeName);

Source Link

Document

Does this model contain an attribute of the given name?

Usage

From source file:com.gisnet.cancelacion.web.controller.Utils.java

public static List<String> getMensajes(Model model) {
    List<String> messages;
    if (model.containsAttribute("mensajes")) {
        messages = (List<String>) model.asMap().get("mensajes");
    } else {/*from w  w  w . j  a va2  s  . c  o m*/
        messages = new ArrayList<>();
        model.addAttribute("mensajes", messages);
    }
    return messages;
}

From source file:com.redhat.rhtracking.web.controller.Utils.java

public static List<String> getMessagesList(Model model) {
    List<String> messages;
    if (model.containsAttribute("messages")) {
        messages = (List<String>) model.asMap().get("messages");
    } else {/*from ww w.ja va  2  s.co  m*/
        messages = new ArrayList<>();
        model.addAttribute("messages", messages);
    }
    return messages;
}

From source file:com.exxonmobile.ace.hybris.storefront.controllers.util.GlobalMessages.java

public static boolean hasErrorMessage(final Model model) {
    return model.containsAttribute(ERROR_MESSAGES_HOLDER);
}

From source file:com.epam.cme.storefront.controllers.util.GlobalMessages.java

protected static void addMessage(final Model model, final String messageHolder, final String messageKey) {
    if (model.containsAttribute(messageHolder)) {
        final Map<String, Object> modelMap = model.asMap();
        final List<String> messageKeys = new ArrayList<String>((List<String>) modelMap.get(messageHolder));
        messageKeys.add(messageKey);/*w w w . j  a  va2s. c  o m*/
        model.addAttribute(messageHolder, messageKeys);
    } else {
        model.addAttribute(messageHolder, Collections.singletonList(messageKey));
    }
}

From source file:com.brienwheeler.web.spring.web.ModelUtils.java

public static void addAttributeIfNotPresent(Model model, Object attributeValue) {
    String attributeName = Conventions.getVariableName(attributeValue);
    if (!model.containsAttribute(attributeName))
        model.addAttribute(attributeName, attributeValue);
}

From source file:controller.EditBikeController.java

@RequestMapping(value = "productEditResult/bike/{id}", method = GET)
public String showChange(@PathVariable String producttype, @PathVariable String id, Model model) {
    if (!model.containsAttribute("id")) { //failsafe voor als Flashattribute toch niet blijkt te werken. Dan opnieuw gebruiker opzoeken via URL path variable 'id'
        System.out.println("Geen product in model");
        model.addAttribute(dao.findProductById(Long.parseLong(id), model.Car.class));
    }/*from  w  w w .j  av  a2 s  . c  om*/
    return "editBikeResult";
}

From source file:controller.EditCarController.java

@RequestMapping(value = "productEditResult/car/{id}", method = GET)
public String showChange(@PathVariable String producttype, @PathVariable String id, Model model) {
    if (!model.containsAttribute("id")) { //failsafe voor als Flashattribute toch niet blijkt te werken. Dan opnieuw gebruiker opzoeken via URL path variable 'id'
        System.out.println("Geen product in model");
        model.addAttribute(dao.findProductById(Long.parseLong(id), model.Car.class));
    }//  ww w.java 2 s. co  m
    return "editCarResult";
}

From source file:controller.AddBikeController.java

@RequestMapping(value = "addedproduct/bike/{producttype}/{id}", method = GET)
public String showProfile(@PathVariable String producttype, @PathVariable String id, Model model) {
    if (!model.containsAttribute("id")) { //failsafe voor als Flashattribute toch niet blijkt te werken. Dan opnieuw gebruiker opzoeken via URL path variable 'username'
        logger.debug("Geen product in model");
        model.addAttribute(dao.findProductById(Long.parseLong(id), model.Bike.class));
    }//  w  w  w . ja va  2 s  .c  o  m

    return "addedBike";
}

From source file:controller.AddCarController.java

@RequestMapping(value = "addedproduct/car/{producttype}/{id}", method = GET)
public String showProfile(@PathVariable String producttype, @PathVariable String id, Model model) {
    if (!model.containsAttribute("id")) { //failsafe voor als Flashattribute toch niet blijkt te werken. Dan opnieuw gebruiker opzoeken via URL path variable 'username'
        logger.debug("Geen product in model");
        model.addAttribute(dao.findProductById(Long.parseLong(id), model.Car.class));
    }/*from   w w w . j a va  2  s. c  o  m*/

    return "addedCar";
}

From source file:nl.npcf.eav.crud.EAVCrudController.java

@RequestMapping
public String render(final Model model) {
    if (!model.containsAttribute(COMMAND)) {
        Command command = new Command();
        command.setBsn("initial");
        model.addAttribute(COMMAND, command);
        log.info("Render: new command object");
    } else {//from w w w.  j  a  v a  2 s. c  o  m
        log.info("Render: existing command object");
    }
    return "eav-crud";
}