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:net.solarnetwork.central.dras.web.DRASOperatorController.java

/**
 * Get list of available programs.//  w  w  w  . j av  a2s.c  o  m
 * 
 * @param request the servlet request
 * @param model the model
 * @return view name
 */
// FIXME: remove GET support, only for testing
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, value = "/createEvent.*")
public String createEvent(HttpServletRequest request, Event input, Model model) {
    Program program = drasObserverBiz.getProgram(input.getProgramId());
    Event result = drasOperatorBiz.createEvent(program, input.getName(), input.getEventDate(),
            input.getEndDate());
    model.asMap().clear();
    model.addAttribute(MODEL_KEY_RESULT, result);
    return WebUtils.resolveViewFromUrlExtension(request, getViewName());
}

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

@Test
public void should_redirect_to_list_with_a_error_message_when_trying_to_post_in_a_non_existent_forum() {

    Model model = model();

    TopicsController controller = new TopicsController();
    controller.setForumRepository(forumRepository(null));

    String result = controller.create("1234", model);
    Message message = (Message) model.asMap().get("message");

    assertThat(result, equalTo("redirect:/view/forums/list"));
    assertThat(message, notNullValue());
    assertThat(message.isError(), is(true));
}

From source file:com.gerrydevstory.myxie.page.PageService.java

/**
 * Builds page with given path. Page is an association of site template, layout and
 * several components (widgets). First the template is fetched then components are
 * substituted into it./*from  w ww  . j  a v a  2  s .c  o  m*/
 * 
 * @param path
 *          path of the requested page. For example if the URL is
 *          http://mycoolblog.com/contact-us then the path is /contact-us. If /
 *          prefix not given it will be appended.
 * @param out
 *          output writer where the resulting page is written
 */
public void buildPage(String path, Writer out, Model model) {
    Template siteTemplate = templateRepo.findByName("master");
    Page page = pageRepo.findByPath(path);
    Layout layout = layoutRepo.findByName(page.getLayoutName());

    Map<String, Object> context = new HashMap<String, Object>();
    context.put("layout", layout);
    context.put("page", page);
    context.putAll(model.asMap());

    siteTemplate.render(context, out);
}

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

@RequestMapping(method = RequestMethod.PUT)
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String update(@Valid Organisation organisation, BindingResult bindingResult, Model uiModel,
        HttpServletRequest request) {/*from  w ww .j  a v  a 2s. c  om*/

    if (bindingResult.hasErrors()) {
        uiModel.addAttribute("organisation", organisation);

        FlashScope.appendMessage(getMessage("metahive_object_validation", Organisation.class), request);

        return "organisations/update";
    }
    uiModel.asMap().clear();
    organisation.merge();

    FlashScope.appendMessage(getMessage("metahive_edit_complete", Organisation.class), request);

    return "redirect:/organisations";
}

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

@RequestMapping(method = RequestMethod.POST)
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String create(@Valid Organisation organisation, BindingResult bindingResult, Model uiModel,
        HttpServletRequest request) {//from www  . j  av  a 2 s  .c om

    if (bindingResult.hasErrors()) {
        uiModel.addAttribute("organisation", organisation);

        FlashScope.appendMessage(getMessage("metahive_object_validation", Organisation.class), request);

        return "organisations/create";
    }
    uiModel.asMap().clear();
    organisation.persist();
    organisation.flush();

    FlashScope.appendMessage(getMessage("metahive_create_complete", Organisation.class), request);

    return "redirect:/organisations";
}

From source file:org.fenixedu.qubdocs.ui.documenttemplates.AcademicServiceRequestTemplateController.java

private AcademicServiceRequestTemplate getAcademicServiceRequestTemplate(Model model) {
    return (AcademicServiceRequestTemplate) model.asMap().get("academicServiceRequestTemplate");
}

From source file:org.fenixedu.qubdocs.ui.documenttemplates.AcademicServiceRequestTemplateController.java

private AcademicServiceRequestTemplateBean getAcademicServiceRequestTemplateBean(Model model) {
    return (AcademicServiceRequestTemplateBean) model.asMap().get("academicServiceRequestTemplateBean");
}

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

@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String create(@Valid Records records, BindingResult bindingResult, Model uiModel,
        HttpServletRequest httpServletRequest) {
    if (bindingResult.hasErrors()) {
        populateEditForm(uiModel, records);
        return "recordses/create";
    }/*from  ww w .  ja va2 s  .c om*/
    uiModel.asMap().clear();
    records.persist();
    return "redirect:/recordses/" + encodeUrlPathSegment(records.getId().toString(), httpServletRequest);
}

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

@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
public String update(@Valid Records records, BindingResult bindingResult, Model uiModel,
        HttpServletRequest httpServletRequest) {
    if (bindingResult.hasErrors()) {
        populateEditForm(uiModel, records);
        return "recordses/update";
    }//  w w w .j  a v  a 2 s . co  m
    uiModel.asMap().clear();
    records.merge();
    return "redirect:/recordses/" + encodeUrlPathSegment(records.getId().toString(), httpServletRequest);
}

From source file:net.solarnetwork.central.dras.web.DRASOperatorController.java

/**
 * Assign participants to an existing event.
 * //www  .ja v a  2  s.c  o m
 * @param request the servlet request
 * @param input input command data
 * @param model the model
 * @return view name
 */
// FIXME: remove GET support, only for testing
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, value = "/assignEventGroups.*")
public String assignEventGroups(HttpServletRequest request, ParticipantsCommand input, Model model) {
    Event event = drasObserverBiz.getEvent(input.getId());
    Set<Identity<Long>> groups = new LinkedHashSet<Identity<Long>>(input.getG());
    EventParticipants result = drasOperatorBiz.assignEventParticipantGroups(event, groups);
    model.asMap().clear();
    model.addAttribute(MODEL_KEY_RESULT, result);
    return WebUtils.resolveViewFromUrlExtension(request, getViewName());
}