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:es.ucm.fdi.dalgs.activity.web.ActivityController.java

/**
 * Methods for adding activities/*w  w  w  .  j a v  a  2  s.  c om*/
 */
@Secured({ "ROLE_ADMIN", "ROLE_PROFESSOR" })
@RequestMapping(value = "/academicTerm/{academicId}/course/{courseId}/group/{groupId}/activity/add.htm", method = RequestMethod.GET)
public String addActivityGroupGET(@PathVariable("academicId") Long id_Long,
        @PathVariable("groupId") Long id_group, @PathVariable("courseId") Long id_course, Model model) {

    if (!model.containsAttribute("addactivity")) {
        Activity newActivity = new Activity();
        model.addAttribute("addactivity", newActivity);
    }
    return "activity/add";

}

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

/**
 * Methods for adding activities/*from w ww. j a  v a 2s.  c o  m*/
 */
@Secured({ "ROLE_ADMIN", "ROLE_PROFESSOR" })
@RequestMapping(value = "/academicTerm/{academicId}/course/{courseId}/activity/add.htm", method = RequestMethod.GET)
public String addActivityCourseGET(@PathVariable("academicId") Long id_Long,
        @PathVariable("courseId") Long id_course, Model model) {

    if (!model.containsAttribute("addactivity")) {

        Activity newActivity = new Activity();
        model.addAttribute("addactivity", newActivity);
    }
    return "activity/add";

}

From source file:fi.koku.kks.controller.ChildController.java

@RenderMapping(params = "action=showChild")
public String show(PortletSession session, @ModelAttribute(value = "child") Person child,
        @RequestParam(value = "error", required = false) String error,
        @RequestParam(value = "message", required = false) String message, RenderResponse response,
        Model model) {
    LOG.debug("show child");

    try {/*from  w ww  .jav  a  2  s. com*/
        String pic = Utils.getPicFromSession(session);

        if (StringUtils.isEmpty(child.getFirstName())) {
            child = getChild(session, child.getPic());
        }

        model.addAttribute("child", child);
        model.addAttribute("collections", kksService.getKksCollections(child.getPic(), pic));
        model.addAttribute("creatables", kksService.searchPersonCreatableCollections(child, pic));
        model.addAttribute("registries", kksService.getAuthorizedRegistries(pic));

        if (!model.containsAttribute("creation")) {
            model.addAttribute("creation", new Creation());
        }

        if (StringUtils.isNotEmpty(error)) {
            model.addAttribute("error", error);
        }

        if (StringUtils.isNotEmpty(message)) {
            model.addAttribute("message", message);
        }

        return "child";

    } catch (ServiceFault e) {
        LOG.error("Failed to get KKS collections", e);
        return "error";
    }
}

From source file:org.iti.agrimarket.view.IndexController.java

@RequestMapping(value = { "index.htm" }, method = RequestMethod.GET)
public String allCategories(Locale locale, Model model) {
    locale = LocaleContextHolder.getLocale();
    List<Category> categorys = null;
    System.out.println("index controller");
    if (servletContext.getAttribute("allcategories") == null) {
        categorys = categoryService.getChildrenOf(1);
    }/*w w  w  .ja v  a 2  s.c o  m*/
    System.out.println("categories = " + categorys);
    servletContext.setAttribute("allcategories", categorys);

    List<UserOfferProductFixed> latestOffers = offerService.getLatestOffers();

    System.out.println("latest offers : " + latestOffers);
    model.addAttribute("latestOffers", latestOffers);
    model.addAttribute("lang", locale);
    System.out.println(model.containsAttribute("latestOffers"));
    return "index";
}

From source file:com.exxonmobile.ace.hybris.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 ProductModel productModel = productService.getProductForCode(productCode);

    updatePageTitle(productModel, model);
    populateProductDetailForDisplay(productModel, model, request);

    if (!model.containsAttribute(WebConstants.MULTI_DIMENSIONAL_PRODUCT)) {
        return REDIRECT_PREFIX + productModelUrlResolver.resolve(productModel);
    }//from w ww.  j  a  v a2 s . c om

    final String metaKeywords = MetaSanitizerUtil.sanitizeKeywords(productModel.getKeywords());
    final String metaDescription = MetaSanitizerUtil.sanitizeDescription(productModel.getDescription());
    setUpMetaData(model, metaKeywords, metaDescription);

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

From source file:com.google.code.trapo.controller.ForumControllerTests.java

@Test
@SuppressWarnings("unchecked")
public void should_return_all_forums_when_listing() {

    Model model = this.model();
    ForumRepository repository = mock(ForumRepository.class);
    when(repository.listAll()).thenReturn(asList(forum(), forum(), forum()));

    ForumsController controller = controllerWith(repository);

    controller.list(model);//from w w w . ja  v a  2  s .  c om

    List<Forum> forums = (List<Forum>) model.asMap().get("forums");

    assertThat(forums.size(), CoreMatchers.equalTo(3));
    assertThat(model.containsAttribute("forums"), is(true));
}

From source file:com.exxonmobile.ace.hybris.storefront.controllers.misc.AddToCartController.java

protected ProductData addToCart(final Model model, final ProductQuantityData productQuantity) {
    ProductData product = null;//from  w ww  .  ja va  2 s  .c o  m

    try {
        final CartModificationData cartModification = cartFacade.addToCart(productQuantity.getSku(),
                productQuantity.getQuantity());

        product = cartModification.getEntry().getProduct();
        model.addAttribute("entry", cartModification.getEntry());
        model.addAttribute("numberShowing", Config.getInt(SHOWN_PRODUCT_COUNT, 3));

        if (cartModification.getQuantityAdded() <= 0L) {
            if (!model.containsAttribute(ERROR_MSG_TYPE)) {
                final String msg = BASKET_QUANTITY_NOITEMADDED_ERROR_PREFIX_KEY
                        + cartModification.getStatusCode();
                model.addAttribute(ERROR_MSG_TYPE, msg);
                GlobalMessages.addMessage(model, GlobalMessages.ERROR_MESSAGES_HOLDER, msg,
                        new Object[] { product.getName() });
            }
        } else if (cartModification.getQuantityAdded() < productQuantity.getQuantity()) {
            if (!model.containsAttribute(ERROR_MSG_TYPE)) {
                final String msg = BASKET_QUANTITY_REDUCED_NUMBER_PREFIX_KEY + cartModification.getStatusCode();
                model.addAttribute(ERROR_MSG_TYPE, msg);
                GlobalMessages.addMessage(model, GlobalMessages.ERROR_MESSAGES_HOLDER, msg,
                        new Object[] { product.getName() });
            }

        }
    } catch (final CommerceCartModificationException ex) {
        GlobalMessages.addMessage(model, GlobalMessages.ERROR_MESSAGES_HOLDER, "basket.error.occurred", null);
    }

    return product;

}

From source file:com.daimler.spm.storefront.controllers.pages.QuoteController.java

protected void fillQuoteForm(final Model model, final AbstractOrderData data) {
    if (!model.containsAttribute("quoteForm")) {
        final Locale currentLocale = getI18nService().getCurrentLocale();
        final String expirationTimePattern = getMessageSource().getMessage(DATE_FORMAT_KEY, null,
                currentLocale);//from  w w w  .j  a  v  a 2  s .  c  o  m

        final QuoteForm quoteForm = new QuoteForm();
        quoteForm.setName(data.getName());
        quoteForm.setDescription(data.getDescription());
        quoteForm.setExpirationTime(QuoteExpirationTimeConverter.convertDateToString(data.getExpirationTime(),
                expirationTimePattern, currentLocale));
        model.addAttribute("quoteForm", quoteForm);
    }
    model.addAttribute("quoteDiscountForm", new QuoteDiscountForm());
}

From source file:com.exxonmobile.ace.hybris.storefront.controllers.pages.MyCompanyPageController.java

protected String addCostCenter(final Model model) throws CMSItemNotFoundException {
    if (!model.containsAttribute("b2BCostCenterForm")) {
        final B2BCostCenterForm b2BCostCenterForm = new B2BCostCenterForm();
        b2BCostCenterForm.setParentB2BUnit(companyB2BCommerceFacade.getParentUnit().getUid());
        model.addAttribute(b2BCostCenterForm);
    }/* w w  w .j a v  a  2s  .c o  m*/
    storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE));
    final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.createManageCostCenterBreadCrumbs();
    breadcrumbs.add(new Breadcrumb(ADD_COSTCENTER_URL, getMessageSource()
            .getMessage("text.company.costCenter.addPage", null, getI18nService().getCurrentLocale()), null));
    model.addAttribute("breadcrumbs", breadcrumbs);
    model.addAttribute("metaRobots", "no-index,no-follow");
    return ControllerConstants.Views.Pages.MyCompany.MyCompanyAddCostCenterPage;
}

From source file:com.exxonmobile.ace.hybris.storefront.controllers.pages.MyCompanyPageController.java

protected String createUser(final Model model) throws CMSItemNotFoundException {
    if (!model.containsAttribute("b2BCustomerForm")) {
        final B2BCustomerForm b2bCustomerForm = new B2BCustomerForm();
        b2bCustomerForm.setParentB2BUnit(companyB2BCommerceFacade.getParentUnit().getUid());

        // Add the b2bcustomergroup role by default
        b2bCustomerForm.setRoles(Collections.singletonList("b2bcustomergroup"));

        model.addAttribute(b2bCustomerForm);
    }/*from w  w  w.  j  av  a  2  s .c  o m*/
    model.addAttribute("titleData", getUserFacade().getTitles());
    model.addAttribute("roles", populateRolesCheckBoxes(companyB2BCommerceFacade.getUserGroups()));

    storeCmsPageInModel(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE));
    setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ORGANIZATION_MANAGEMENT_CMS_PAGE));
    final List<Breadcrumb> breadcrumbs = myCompanyBreadcrumbBuilder.getBreadcrumbs(null);
    breadcrumbs.add(new Breadcrumb("/my-company/organization-management/manage-users/create",
            getMessageSource().getMessage("text.company.organizationManagement.createuser", null,
                    getI18nService().getCurrentLocale()),
            null));
    breadcrumbs.add(new Breadcrumb("/my-company/organization-management/manage-user", getMessageSource()
            .getMessage("text.company.manageUsers", null, getI18nService().getCurrentLocale()), null));
    model.addAttribute("breadcrumbs", breadcrumbs);
    model.addAttribute("metaRobots", "no-index,no-follow");
    return ControllerConstants.Views.Pages.MyCompany.MyCompanyManageUserAddEditFormPage;
}