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:no.dusken.barweb.admin.InvoiceControllerTest.java

@Test
public void testListInvoicesGjeng() {
    List<Invoice> invoices = new LinkedList<Invoice>();
    when(invoiceService.getByGjeng(any(Gjeng.class))).thenReturn(invoices);
    Model m = new ExtendedModelMap();
    String view = controller.listInvoices(666L, m);
    assertEquals("Wrong view", "no/dusken/barweb/admin/invoice/list", view);
    assertNotNull(m.asMap().get("invoices"));
    assertTrue("Should contain gjeng", m.containsAttribute("gjeng"));
}

From source file:eu.dime.dnsregister.controllers.RecordsController.java

@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "text/html")
public String delete(@PathVariable("id") Integer id,
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "size", required = false) Integer size, Model uiModel) {
    Records records = Records.findRecords(id);
    records.remove();/*from  w w w  . j  ava 2 s . c o  m*/
    uiModel.asMap().clear();
    uiModel.addAttribute("page", (page == null) ? "1" : page.toString());
    uiModel.addAttribute("size", (size == null) ? "10" : size.toString());
    return "redirect:/recordses";
}

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

@RequestMapping(method = RequestMethod.GET, params = "draft")
public String editDraft(@PathVariable String language, @RequestParam long id, String query, Model model,
        RedirectAttributes redirectAttributes) {
    Page page = (Page) model.asMap().get("page");
    if (!language.equals(page.getLanguage())) {
        redirectAttributes.addAttribute("language", language);
        redirectAttributes.addAttribute("query", query);
        return "redirect:/_admin/{language}/pages/index";
    }/*from  w  w  w .j ava2 s .co m*/

    Page draft = pageService.getDraftById(id);
    if (draft == null) {
        redirectAttributes.addAttribute("language", language);
        redirectAttributes.addAttribute("id", id);
        redirectAttributes.addAttribute("query", query);
        return "redirect:/_admin/{language}/pages/edit";
    }
    Set<CustomField> customFields = customFieldService.getAllCustomFields(language);
    PageEditForm form = PageEditForm.fromDomainObject(draft, customFields);
    model.addAttribute("form", form);

    return "page/edit";
}

From source file:org.fenixedu.bennu.spring.FenixEDUBaseController.java

protected String redirect(final String destinationAction, final Model model,
        final RedirectAttributes redirectAttributes) {
    if (model.containsAttribute(INFO_MESSAGES)) {
        redirectAttributes.addFlashAttribute(INFO_MESSAGES, model.asMap().get(INFO_MESSAGES));
    }/*w  w  w. j a  va 2s. com*/
    if (model.containsAttribute(WARNING_MESSAGES)) {
        redirectAttributes.addFlashAttribute(WARNING_MESSAGES, model.asMap().get(WARNING_MESSAGES));
    }
    if (model.containsAttribute(ERROR_MESSAGES)) {
        redirectAttributes.addFlashAttribute(ERROR_MESSAGES, model.asMap().get(ERROR_MESSAGES));
    }

    return "redirect:" + destinationAction;
}

From source file:com.mtt.myapp.user.controller.UserControllerTest.java

@SuppressWarnings("unchecked")
@Test/*from w w  w . j  av a  2 s .  c  o  m*/
public void testDelete() {
    // save new user for test
    saveTestUser("NewUserId1", "NewUserName1");
    saveTestUser("NewUserId2", "NewUserName2");
    saveTestUser("NewUserId3", "NewUserName3");

    Pageable page = new PageRequest(0, 10);
    Model model = new ExtendedModelMap();

    // search
    UserSearchForm form = new UserSearchForm();
    form.setName("NewUserName");
    userController.search(form, page, model);
    Page userList = (Page<User>) model.asMap().get("users");
    assertThat(userList.getContent().size()).isSameAs(3);

    // test to delete one
    userController.delete("NewUserId1");
    model = new ExtendedModelMap();
    userController.search(form, page, model);
    userList = (Page<User>) model.asMap().get("users");
    assertThat(userList.getContent().size()).isSameAs(2);

    // test to delete more
    model = new ExtendedModelMap();
    userController.delete("NewUserId2,NewUserId3");
    userController.search(form, page, model);
    userList = (Page<User>) model.asMap().get("users");
    assertThat(userList.getContent().size()).isSameAs(0);
}

From source file:computech.controller.CatalogControllerIntegrationTests.java

@Test
@SuppressWarnings("unchecked")
public void zubehoerControllerIntegrationTest() {
    Model model = new ExtendedModelMap();
    String returnedView = controller.zubeCatalog(model);
    assertThat(returnedView, is("zubehoer"));
    Iterable<Object> object = (Iterable<Object>) model.asMap().get("catalog");
    assertThat(object, is(iterableWithSize(2)));

}

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

@RequestMapping(method = RequestMethod.GET, params = "draft")
public String editDraft(@PathVariable String language, @RequestParam long id, String query, Model model,
        RedirectAttributes redirectAttributes) {
    Article article = (Article) model.asMap().get("article");
    if (!language.equals(article.getLanguage())) {
        redirectAttributes.addAttribute("language", language);
        redirectAttributes.addAttribute("query", query);
        return "redirect:/_admin/{language}/articles/index";
    }/*from  w w w .j av a  2  s .  co m*/

    Article draft = articleService.getDraftById(id);
    if (draft == null) {
        redirectAttributes.addAttribute("language", language);
        redirectAttributes.addAttribute("id", id);
        redirectAttributes.addAttribute("query", query);
        return "redirect:/_admin/{language}/articles/edit";
    }
    SortedSet<CustomField> customFields = customFieldService.getAllCustomFields(language);
    ArticleEditForm form = ArticleEditForm.fromDomainObject(draft, customFields);
    model.addAttribute("form", form);

    return "article/edit";
}

From source file:computech.controller.CatalogControllerIntegrationTests.java

/**
 * Integration test for an individual controller.
 *//*from  www .  ja  v  a 2s  . c o m*/
@Test
@SuppressWarnings("unchecked")
public void laptopControllerIntegrationTest() {

    Model model = new ExtendedModelMap();
    String returnedView = controller.notebookCatalog(model);
    assertThat(returnedView, is("laptop"));
    Iterable<Object> object = (Iterable<Object>) model.asMap().get("catalog");
    assertThat(object, is(iterableWithSize(2)));
}

From source file:computech.controller.CatalogControllerIntegrationTests.java

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

    Model model = new ExtendedModelMap();
    String returnedView = controller.softwareCatalog(model);
    assertThat(returnedView, is("software"));
    Iterable<Object> object = (Iterable<Object>) model.asMap().get("catalog");

    assertThat(object, is(iterableWithSize(2)));
}

From source file:no.dusken.barweb.admin.InvoiceControllerTest.java

@Test
public void testHandleInvoicePaid() throws Exception {

    Model m = new ExtendedModelMap();
    String view = controller.handleInvoicePaid(1L, m);
    assertEquals("Wrong view", "no/dusken/barweb/admin/invoice/paid", view);
    Invoice invoice = (Invoice) m.asMap().get("invoice");
    assertNotNull("Did not contain invoice", invoice);
    assertTrue("Invoice should be paid", invoice.getPaid());
    verify(personInvoiceService).savePersonsAndInvoice(any(List.class), any(Invoice.class));
}