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:org.openmrs.module.metadatasharing.web.controller.ExportController.java

@RequestMapping(value = CREATE_PATH, method = RequestMethod.POST)
public String create(@ModelAttribute(EXPORTER) PackageExporter exporter, Errors errors, Model model) {
    model.addAttribute("publishConfigured", MetadataSharing.getInstance().isPublishConfigured());

    if (exporter.getExportedPackage().isPublished()) {
        exporter.getExportedPackage()/*from   w w w . j  a v a2  s  .com*/
                .setSubscriptionUrl(PublishUtils.createAbsolutePublishURL(exporter.getExportedPackage()));
    }

    validator.validate(exporter, errors);

    if (errors.hasErrors()) {
        return null;
    } else {
        if (!model.containsAttribute(PACKAGE_ITEMS)) {
            model.addAttribute(PACKAGE_ITEMS, new PackageItems());
        }
        return WebUtils.redirect(EDIT_PATH);
    }
}

From source file:de.hybris.platform.commerceorgaddon.controllers.pages.CostCenterManagementPageController.java

@RequestMapping(value = "/enable", method = RequestMethod.GET)
@RequireHardLogIn//w w  w  .j a v  a2  s .c  om
public String enableCostCenter(@RequestParam("costCenterCode") final String costCenterCode, final Model model)
        throws CMSItemNotFoundException {
    try {
        b2bCostCenterFacade.enableDisableCostCenter(costCenterCode, true);
    } catch (final Exception e) {
        LOG.error(e.getMessage(), e);
        GlobalMessages.addErrorMessage(model, "form.global.error");
    }

    final B2BCostCenterData b2bCostCenterData = b2bCostCenterFacade.getCostCenterDataForCode(costCenterCode);

    if (b2bCostCenterData.getUnit() != null && !b2bCostCenterData.getUnit().isActive()) {
        GlobalMessages.addErrorMessage(model, "text.costcenter.parentunit.disabled.error");
    }

    if (model.containsAttribute(GlobalMessages.ERROR_MESSAGES_HOLDER)) {
        return viewCostCenterDetails(costCenterCode, model);
    }

    return String.format(REDIRECT_TO_COSTCENTER_DETAILS, urlEncode(costCenterCode));
}

From source file:com.aerospike.controller.ClientController.java

@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(Model model) {
    List<String> serviceNames = new ArrayList<String>();

    boolean bound = (services == null);

    if (services != null) {
        for (String serviceName : services.keySet()) {

            if (serviceNameA == null) {
                serviceNameA = serviceName;
            }//from   w w w  .  jav  a 2s.co m
            serviceNames.add(serviceName);
            bound = true;
        }
    }
    if (workloadConfig == null)
        workloadConfig = workloads.get(workloads.keySet().toArray()[0]);

    model.addAttribute("services", serviceNames);
    model.addAttribute("bound", bound);
    model.addAttribute("serviceNameA", this.serviceNameA);
    model.addAttribute("isConfig", true);
    if (!model.containsAttribute("workloadConfig")) {
        model.addAttribute("workloadConfig", this.workloadConfig);
    }
    model.addAttribute("workloads", this.workloads.values());
    return "index";
}

From source file:de.hybris.platform.commerceorgaddon.controllers.pages.BudgetManagementPageController.java

@RequestMapping(value = "/enable", method = RequestMethod.GET)
@RequireHardLogIn//w w w .j  av a  2 s.c  o m
public String enableBudget(@RequestParam("budgetCode") final String budgetCode, final Model model)
        throws CMSItemNotFoundException {

    final B2BBudgetData b2bBudgetData = budgetFacade.getBudgetDataForCode(budgetCode);

    if (b2bBudgetData.getUnit() != null && !b2bBudgetData.getUnit().isActive()) {
        GlobalMessages.addErrorMessage(model, "error.budget.parentunit.disabled");
    } else {
        try {
            budgetFacade.enableDisableBudget(budgetCode, true);
        } catch (final Exception e) {
            LOG.error(e.getMessage(), e);
            GlobalMessages.addErrorMessage(model, "form.global.error");
        }

        if (model.containsAttribute(GlobalMessages.ERROR_MESSAGES_HOLDER)) {
            return viewBudgetsDetails(budgetCode, model);
        }

    }

    return String.format(REDIRECT_TO_BUDGET_DETAILS, urlEncode(budgetCode));
}

From source file:com.mitre.storefront.controllers.pages.CartPageController.java

@ResponseBody
@RequestMapping(value = "/update", method = RequestMethod.POST)
public CartData updateCartQuantities(@RequestParam("entryNumber") final Integer entryNumber,
        @RequestParam("productCode") final String productCode, final Model model,
        @Valid final UpdateQuantityForm form, final BindingResult bindingErrors)
        throws CMSItemNotFoundException {
    if (bindingErrors.hasErrors()) {
        getViewWithBindingErrorMessages(model, bindingErrors);
    } else {/*w ww .ja  v a  2  s  .c  o m*/
        final CartModificationData cartModification = b2bCartFacade
                .updateOrderEntry(getOrderEntryData(form.getQuantity(), productCode, entryNumber));

        if (cartModification.getStatusCode().equals(SUCCESSFUL_MODIFICATION_CODE)) {
            GlobalMessages.addMessage(model, GlobalMessages.CONF_MESSAGES_HOLDER,
                    cartModification.getStatusMessage(), null);
        } else if (!model.containsAttribute(ERROR_MSG_TYPE)) {
            GlobalMessages.addMessage(model, GlobalMessages.ERROR_MESSAGES_HOLDER,
                    cartModification.getStatusMessage(), null);
        }
    }

    return cartFacade.getSessionCart();
}

From source file:com.jnj.b2b.storefront.controllers.pages.CartPageController.java

@ResponseBody
@RequestMapping(value = "/update", method = RequestMethod.POST)
@RequireHardLogIn/*from   ww  w  . j  a va 2 s. co  m*/
public CartData updateCartQuantities(@RequestParam("entryNumber") final Integer entryNumber,
        @RequestParam("productCode") final String productCode, final Model model,
        @Valid final UpdateQuantityForm form, final BindingResult bindingErrors)
        throws CMSItemNotFoundException {
    if (bindingErrors.hasErrors()) {
        getViewWithBindingErrorMessages(model, bindingErrors);
    } else {
        final CartModificationData cartModification = b2bCartFacade
                .updateOrderEntry(getOrderEntryData(form.getQuantity(), productCode, entryNumber));

        if (cartModification.getStatusCode().equals(SUCCESSFUL_MODIFICATION_CODE)) {
            GlobalMessages.addMessage(model, GlobalMessages.CONF_MESSAGES_HOLDER,
                    cartModification.getStatusMessage(), null);
        } else if (!model.containsAttribute(ERROR_MSG_TYPE)) {
            GlobalMessages.addMessage(model, GlobalMessages.ERROR_MESSAGES_HOLDER,
                    cartModification.getStatusMessage(), null);
        }
    }

    return cartFacade.getSessionCart();
}

From source file:es.ucm.fdi.dalgs.activity.web.ActivityController.java

/**
 * Methods for modifying activities/* ww  w  .ja  v  a2s.  com*/
 */

@RequestMapping(value = "/academicTerm/{academicId}/course/{courseId}/group/{groupId}/activity/{activityId}/modify.htm", method = RequestMethod.GET)
public String modifyActivityGroupGET(@PathVariable("academicId") Long id_academic,
        @PathVariable("courseId") Long id_course, @PathVariable("groupId") Long id_group,
        @PathVariable("activityId") Long id_activity, Model model) throws ServletException {

    Activity p = serviceActivity.getActivity(id_activity, id_course, id_group, id_academic).getSingleElement();

    if (p != null) {
        model.addAttribute("courseId", id_course);

        if (!model.containsAttribute("modifyactivity")) {
            model.addAttribute("modifyactivity", p);

        }

        Collection<LearningGoal> lg = serviceLearningGoal.getLearningGoalsFromCourse(id_course, p);

        model.addAttribute("learningGoalStatus", p.getLearningGoalStatus());
        model.addAttribute("learningGoals", lg);

        model.addAttribute("attachments", p.getAttachments());

        FileUpload file = new FileUpload();
        model.addAttribute("addfileupload", file);

        LearningGoalStatus cs = new LearningGoalStatus();
        model.addAttribute("addlearningstatus", cs);

        return "activity/modifyChoose";
    }
    return "redirect:/academicTerm/{academicId}/course/{courseId}/group/{groupId}.htm";
}

From source file:es.ucm.fdi.dalgs.activity.web.ActivityController.java

/**
 * Methods for modifying activities/* ww w. j  a  v  a 2  s.c o  m*/
 */

@RequestMapping(value = "/academicTerm/{academicId}/course/{courseId}/activity/{activityId}/modify.htm", method = RequestMethod.GET)
public String modifyActivityCourseGET(@PathVariable("academicId") Long id_academic,
        @PathVariable("courseId") Long id_course, @PathVariable("activityId") Long id_activity, Model model)
        throws ServletException {

    Activity p = serviceActivity.getActivity(id_activity, id_course, null, id_academic).getSingleElement();
    model.addAttribute("courseId", id_course);

    if (p != null) {
        if (!model.containsAttribute("modifyactivity")) {
            model.addAttribute("modifyactivity", p);

        }

        Collection<LearningGoal> lg = serviceLearningGoal.getLearningGoalsFromCourse(id_course, p);

        model.addAttribute("learningGoalStatus", p.getLearningGoalStatus());
        model.addAttribute("learningGoals", lg);

        model.addAttribute("attachments", p.getAttachments());

        LearningGoalStatus cs = new LearningGoalStatus();
        model.addAttribute("addlearningstatus", cs);

        FileUpload file = new FileUpload();
        model.addAttribute("addfileupload", file);

        return "activity/modifyChoose";
    }

    return "redirect:/academicTerm/{academicId}/course/{courseId}.htm";
}

From source file:se.vgregion.accountmanagement.accountsettings.controller.AccountSettingsController.java

/**
 * Loads the user attributes from LDAP and adds them to the model.
 *
 * @param request  request//from   w  ww. j  av  a2  s . com
 * @param response response
 * @param model    model
 * @return the accountSettingsForm view
 */
@RenderMapping
public String showAccountSettingsForm(RenderRequest request, RenderResponse response, Model model) {

    String loggedInUser = lookupP3PInfo(request, PortletRequest.P3PUserInfos.USER_LOGIN_ID);

    if (loggedInUser == null) {
        model.addAttribute("errorMessage", "Tekniskt fel. Din anvndare hittas inte.");
        return "errorPage";
    }
    if (!loggedInUser.startsWith("ex_")) {
        model.addAttribute("errorMessage",
                "Denna tillmpning r endast tillgnglig fr icke VGR-anstllda.");
        return "errorPage";
    }

    String selectedTab = request.getParameter("tab");
    if (selectedTab != null) {
        model.addAttribute("selectedTab", selectedTab);
    } else if (!model.containsAttribute("selectedTab")) {
        model.addAttribute("selectedTab", 1);
    }

    String[] errorMessages = request.getParameterMap().get("errorMessage");
    if (errorMessages != null && errorMessages.length > 0) {
        // There should only be one
        model.addAttribute("errorMessage", errorMessages[0]);
    }

    String[] successMessages = request.getParameterMap().get("successMessage");
    if (successMessages != null && successMessages.length > 0) {
        model.addAttribute("successMessage", successMessages[0]);
    }

    LdapUser user = ldapAccountService.getUser(loggedInUser);

    if (user == null) {
        model.addAttribute("errorMessage", "Din anvndare finns inte i KIV.");
        return "errorPage";
    }

    model.addAttribute("firstName", user.getAttributeValue("givenName"));
    model.addAttribute("middleName", user.getAttributeValue("middleName"));
    model.addAttribute("lastName", user.getAttributeValue("sn"));
    model.addAttribute("email", user.getAttributeValue("mail"));
    model.addAttribute("telephone", user.getAttributeValue("telephoneNumber"));
    model.addAttribute("mobile", user.getAttributeValue("mobile"));
    model.addAttribute("organization", user.getAttributeValue("externalStructurepersonDN"));

    return "accountSettingsForm";
}

From source file:com.mitre.storefront.controllers.pages.ProductPageController.java

@RequestMapping(value = PRODUCT_CODE_PATH_VARIABLE_PATTERN + "/orderForm", method = RequestMethod.GET)
public String productOrderForm(@PathVariable("productCode") final String productCode, final Model model,
        final HttpServletRequest request, final HttpServletResponse response) throws CMSItemNotFoundException {
    final List<ProductOption> extraOptions = Arrays.asList(ProductOption.VARIANT_MATRIX_BASE,
            ProductOption.VARIANT_MATRIX_PRICE, ProductOption.VARIANT_MATRIX_MEDIA,
            ProductOption.VARIANT_MATRIX_STOCK);

    final ProductData productData = productFacade.getProductForCodeAndOptions(productCode, extraOptions);
    updatePageTitle(productData, model);

    populateProductDetailForDisplay(productCode, model, request, extraOptions);

    if (!model.containsAttribute(WebConstants.MULTI_DIMENSIONAL_PRODUCT)) {
        return REDIRECT_PREFIX + productDataUrlResolver.resolve(productData);
    }/*from w  w  w  .  j  a v  a2 s  .  co m*/

    return ControllerConstants.Views.Pages.Product.OrderForm;
}