Example usage for org.springframework.ui Model asMap

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

Introduction

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

Prototype

Map<String, Object> asMap();

Source Link

Document

Return the current set of model attributes as a Map.

Usage

From source file:org.sventon.web.ctrl.ConfigurationFormControllerTest.java

@Test
public void onFormSubmitRepositoryAdded() throws Exception {

    Application application = mock(Application.class);

    HashSet<RepositoryName> repositoryNames = new HashSet<RepositoryName>();
    repositoryNames.add(new RepositoryName("sventon"));
    repositoryNames.add(new RepositoryName("nordpolen"));
    when(application.getRepositoryNames()).thenReturn(repositoryNames);

    ConfigCommand command = new ConfigCommand();
    command.setName("nordpolen");
    command.setRepositoryUrl("svn://northpole.com/repo");

    BindingResult bindingResult = mock(BindingResult.class);
    when(bindingResult.hasErrors()).thenReturn(false);

    Model model = new ExtendedModelMap();

    ConfigurationFormController controller = new ConfigurationFormController(application);
    String listConfigView = controller.onFormSubmit(command, bindingResult, model);

    Map expectedModel = new HashMap();
    expectedModel.put("addedRepositories", repositoryNames);
    expectedModel.put("latestAddedRepository", command.getName());

    assertThat(listConfigView, is(LIST_CONFIGS_VIEW_NAME));
    assertThat(model.asMap(), is(expectedModel));

}

From source file:org.kew.rmf.matchconf.web.CustomWiredTransformerController.java

@RequestMapping(value = "/{configType}_configs/{configName}/wires/{wireName}/{transformerType}_transformers/{wiredTransformerName}", method = RequestMethod.DELETE, produces = "text/html")
public String delete(@PathVariable("configType") String configType,
        @PathVariable("configName") String configName, @PathVariable("wireName") String wireName,
        @PathVariable("transformerType") String transformerType,
        @PathVariable("wiredTransformerName") String wiredTransformerName,
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "size", required = false) Integer size, Model uiModel) throws Exception {
    Wire wire = Configuration.findConfigurationsByNameEquals(configName).getSingleResult()
            .getWireForName(wireName);/*from  w ww .  j a  v  a 2 s. c om*/
    WiredTransformer wiredTransformer = wire.getWiredTransformer(transformerType, wiredTransformerName);
    new GetterSetter<List<WiredTransformer>>().getattr(wire, transformerType + "Transformers")
            .remove(wiredTransformer);
    wire.merge();
    uiModel.asMap().clear();
    uiModel.addAttribute("page", (page == null) ? "1" : page.toString());
    uiModel.addAttribute("size", (size == null) ? "10" : size.toString());
    return String.format("redirect:/%s_configs/%s/wires/%s/%s_transformers", configType, configName, wireName,
            transformerType);
}

From source file:com.epam.training.storefront.controllers.pages.payment.PaymentDetailsPageController.java

private String getLabelOrId(final Model model) {
    if (StringUtils.equals(ACCOUNT_AREA, (String) model.asMap().get("targetArea"))) {
        return PAYMENT_DETAILS_CMS_PAGE;
    } else if (StringUtils.equals(MULTI_CHECKOUT_AREA, (String) model.asMap().get("targetArea"))) {
        return MULTI_CHECKOUT_SUMMARY_CMS_PAGE_LABEL;
    }/*  w w  w . j a va 2 s.c  om*/

    return StringUtils.EMPTY;
}

From source file:org.wallride.web.controller.admin.page.PageEditController.java

@RequestMapping(method = RequestMethod.POST, params = "draft")
public @ResponseBody DomainObjectSavedModel saveAsDraft(@PathVariable String language,
        @Validated @ModelAttribute("form") PageEditForm form, BindingResult errors, Model model,
        AuthorizedUser authorizedUser) throws BindException {
    if (errors.hasErrors()) {
        for (ObjectError error : errors.getAllErrors()) {
            if (!"validation.NotNull".equals(error.getCode())) {
                throw new BindException(errors);
            }//from  w w w  .j  ava 2 s  . com
        }
    }

    Page page = (Page) model.asMap().get("page");
    try {
        pageService.savePageAsDraft(form.buildPageUpdateRequest(), authorizedUser);
    } catch (EmptyCodeException e) {
        errors.rejectValue("code", "NotNull");
    } catch (DuplicateCodeException e) {
        errors.rejectValue("code", "NotDuplicate");
    }
    if (errors.hasErrors()) {
        logger.debug("Errors: {}", errors);
        throw new BindException(errors);
    }

    return new DomainObjectSavedModel<>(page);
}

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

@Test
public void verify_that_update_method_add_a_information_message() {

    Forum forum = forum();// w ww .j ava  2  s.  c om
    forum.setId("1234");

    Model model = this.model();

    ForumRepository repository = repository();
    Validator validator = mock(Validator.class);
    ForumsController controller = controllerWith(repository, validator);
    controller.save(forum, errors(), model);

    Message message = (Message) model.asMap().get("message");
    assertThat(message, notNullValue());
    verify(repository).update(forum);

}

From source file:org.kew.rmf.matchconf.web.CustomConfigController.java

@RequestMapping(value = "/{configType}_configs", method = RequestMethod.PUT, produces = "text/html")
public String update(@PathVariable String configType, @Valid Configuration configuration,
        BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
    uiModel.addAttribute("availableItems", LibraryScanner.availableItems());
    configuration.setClassName(ConfigSwitch.TYPE_CLASS_MAP.get(configType));
    this.customValidation(configuration, bindingResult);
    if (bindingResult.hasErrors()) {
        populateEditForm(uiModel, configuration);
        return configType + "_configs/update";
    }/*from w ww  .jav a2 s  .  com*/
    uiModel.asMap().clear();
    configuration.merge();
    return String.format("redirect:/%s_configs/", configType)
            + encodeUrlPathSegment(configuration.getName(), httpServletRequest);
}

From source file:org.wallride.web.controller.admin.article.ArticleEditController.java

@RequestMapping(method = RequestMethod.POST, params = "draft")
public @ResponseBody DomainObjectSavedModel saveAsDraft(@PathVariable String language,
        @Validated @ModelAttribute("form") ArticleEditForm form, BindingResult errors, Model model,
        AuthorizedUser authorizedUser) throws BindException {
    if (errors.hasErrors()) {
        for (ObjectError error : errors.getAllErrors()) {
            if (!"validation.NotNull".equals(error.getCode())) {
                throw new BindException(errors);
            }/*ww  w  .j  a  va 2 s .  com*/
        }
    }

    Article article = (Article) model.asMap().get("article");
    try {
        articleService.saveArticleAsDraft(form.buildArticleUpdateRequest(), authorizedUser);
    } catch (EmptyCodeException e) {
        errors.rejectValue("code", "NotNull");
    } catch (DuplicateCodeException e) {
        errors.rejectValue("code", "NotDuplicate");
    }
    if (errors.hasErrors()) {
        logger.debug("Errors: {}", errors);
        throw new BindException(errors);
    }

    return new DomainObjectSavedModel<>(article);
}

From source file:net.triptech.metahive.web.CommentController.java

@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String delete(@PathVariable("id") Long id, Model uiModel, HttpServletRequest request) {

    Comment comment = Comment.findComment(id);

    String redirect = "redirect:/";

    if (comment.getDefinition() != null) {
        redirect = "redirect:/definitions/"
                + encodeUrlPathSegment(comment.getDefinition().getId().toString(), request);
    }/*from  w w w .j av a2s.c  o  m*/
    if (comment.getRecord() != null) {
        redirect = "redirect:/records/" + encodeUrlPathSegment(comment.getRecord().getId().toString(), request);
    }

    comment.remove();
    uiModel.asMap().clear();

    FlashScope.appendMessage(getMessage("metahive_delete_complete", Comment.class), request);

    return redirect;
}

From source file:org.duracloud.account.app.controller.AccountsController.java

@RequestMapping(value = ACCOUNT_SETUP_MAPPING, method = RequestMethod.POST)
@Transactional/* w  w  w.  jav  a  2 s  . c o  m*/
public ModelAndView setupAccount(@PathVariable Long id,
        @ModelAttribute(SETUP_ACCOUNT_FORM_KEY) @Valid AccountSetupForm accountSetupForm, BindingResult result,
        Model model, RedirectAttributes redirectAttributes) throws Exception {
    log.info("setup account {}", id);

    RootAccountManagerService rams = getRootAccountManagerService();
    AccountInfo info = rams.getAccount(id);

    model.addAttribute(AbstractAccountController.ACCOUNT_INFO_KEY, info);

    if (result.hasErrors()) {
        model.addAttribute("pending", info.getStatus().equals(AccountStatus.PENDING));
        return new ModelAndView(ACCOUNT_SETUP_VIEW, model.asMap());
    }

    //save primary
    saveStorageProvider(accountSetupForm.getPrimaryStorageProviderSettings());

    //save secondary
    for (StorageProviderSettings sp : accountSetupForm.getSecondaryStorageProviderSettingsList()) {
        saveStorageProvider(sp);
    }

    String message = MessageFormat.format("Successfully configured providers for {0}", info.getAcctName());

    AccountStatus status = info.getStatus();
    //activate only if pending
    if (AccountStatus.PENDING.equals(status)) {
        getRootAccountManagerService().activateAccount(id);
        message += " and activated acccount";
    }

    setSuccessFeedback(message, redirectAttributes);

    return createRedirectMav(BASE_MAPPING);
}

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);/*  w  w w .j  av  a2s .c  o  m*/

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

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