Example usage for org.springframework.ui Model addAttribute

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

Introduction

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

Prototype

Model addAttribute(String attributeName, @Nullable Object attributeValue);

Source Link

Document

Add the supplied attribute under the supplied 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 {//w ww.  j  a v a  2s  .  c om
        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 {//ww w  .  j  av a 2 s  .co  m
        messages = new ArrayList<>();
        model.addAttribute("messages", messages);
    }
    return messages;
}

From source file:com.mobileman.projecth.web.util.CaptchaUtil.java

static public boolean verify(HttpServletRequest request, Model model) {
    Captcha captcha = (Captcha) request.getSession().getAttribute(Captcha.NAME);
    String answer = request.getParameter("captchaAnswer");
    if (captcha.isCorrect(answer)) {
        return true;
    }//from   ww w  .ja  v  a 2s  .c  o m
    model.addAttribute(KEY_ERROR, true);
    return false;
}

From source file:com.mobileman.projecth.web.util.PatientUtils.java

/**
 * @param model//from ww  w  . ja  va  2 s.c o m
 * @param data
 * @param visitor
 * @param patient
 * @param selectedDisease
 * @param connectionExists
 */
public static void loadPatientHeader(Model model, DataHolder data, User visitor, Patient patient,
        Disease selectedDisease, boolean connectionExists) {
    loadPatientHeader(model, data, patient, selectedDisease);
    model.addAttribute("visitorCanSeeUserData",
            PrivacyUtils.visitorCanSeeUserData(visitor, patient, connectionExists));
}

From source file:org.zht.framework.web.controller.BaseController.java

protected static void setPageInfoAttribute(Model model, ParamObject paramObject) {
    if (model == null || paramObject == null) {
        return;//w  w w.  j a  va  2 s.  c o  m
    }
    model.addAttribute("webParams", paramObject.getWebParams()).addAttribute("paramObject", paramObject);
}

From source file:eionet.transfer.util.BreadCrumbs.java

/**
 * Create a indefinite list of breadcrumbs.
 *//*  ww  w  .  j  ava2s .co  m*/
public static void set(Model model, BreadCrumb... crumbs) {
    List<BreadCrumb> breadcrumbList = new ArrayList<BreadCrumb>();

    //breadcrumbList.add(eionetCrumb);
    breadcrumbList.add(homeCrumb);

    for (BreadCrumb crumb : crumbs) {
        breadcrumbList.add(crumb);
    }
    model.addAttribute("breadcrumbs", breadcrumbList);
}

From source file:com.mobileman.projecth.web.util.DoctorUtils.java

/**
 * @param model/*from   w  w  w  .  j  a  v  a2s. c o m*/
 * @param data
 * @param user
 */
public static void loadDoctorHeader(Model model, DataHolder data, User user) {

    if (Doctor.class.isInstance(user)) {
        MedicalInstitution mi = Doctor.class.cast(user).getMedicalInstitution();
        String miString = MedicalInstitutionUtil.fmtMedicalInstitution(mi);
        model.addAttribute("medicalInstitution", miString);
        if (mi != null) {
            model.addAttribute("medicalInstitutionPhoneNmr",
                    (mi.getPhoneNumber() != null ? mi.getPhoneNumber().format() : ""));
            model.addAttribute("medicalInstitutionFaxNmr",
                    (mi.getFaxNumber() != null ? mi.getFaxNumber().format() : ""));
        }

    }
    model.addAttribute("visitorCanSeeUserData", Boolean.TRUE);

    String gend = UserUtil.fmtGender(user);
    LocaleService localeService = InitController.getWebApplicationContext().getBean(LocaleService.class);
    model.addAttribute("user_gender", gend.trim().length() == 0 ? localeService.getUnknowMessage() : gend);
    model.addAttribute("user_avatar", PatientUtils.computeAvatar(user.getSex()));
    model.addAttribute("user_age", PatientUtils.computeAge(user.getBirthday()));

}

From source file:org.zht.framework.web.controller.BaseController.java

/**
 * /*from   ww  w .  j ava 2 s . c  o m*/
 * @param model
 * @param data
 * @param dataName
 */
protected static void setDataAttribute(Model model, Object data, String dataName) {
    if (model == null || data == null || dataName == null) {
        return;
    }
    model.addAttribute(dataName, data);
}

From source file:org.zht.framework.web.controller.BaseController.java

protected static void setDataAttribute(Model model, List<?> dataList, String dataName, Long totalCount) {
    if (model == null || dataList == null || dataName == null) {
        return;/*from w  w w  .jav  a 2  s . c om*/
    }
    model.addAttribute(dataName, dataList).addAttribute("totalCount", totalCount == null ? 0L : totalCount);
}

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);//from  ww  w  .j  a  v  a2  s .  com
        model.addAttribute(messageHolder, messageKeys);
    } else {
        model.addAttribute(messageHolder, Collections.singletonList(messageKey));
    }
}