Example usage for org.springframework.ui ModelMap ModelMap

List of usage examples for org.springframework.ui ModelMap ModelMap

Introduction

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

Prototype

public ModelMap() 

Source Link

Document

Construct a new, empty ModelMap .

Usage

From source file:org.ala.spatial.services.web.BreakdownController.java

private ModelMap performBreakdown(String breakdown, String by, HttpServletRequest req) {

    ModelMap m = new ModelMap();

    if (!Utilities.isLoggedIn(req)) {
        m.addAttribute("error", "authentication");
        m.addAttribute("message", "Please authenticate yourself with the ALA system");
    } else {//  w  w  w. j a  va 2 s . c o  m
        String useremail = Utilities.getUserEmail(req);

        if (!Arrays.asList(AVAILABLE_BREAKDOWN_PARAMS).contains(breakdown)) {
            m.addAttribute("error", "empty");
            m.addAttribute("message", "No breakdown available");
        } else {
            String forUser = req.getParameter("usr");
            if (forUser != null && !forUser.trim().equals("") && forUser.trim().equals("all")) {
                if (Utilities.isUserAdmin(req)) {
                    m.addAttribute("breakdown", actionDao.getActionBreakdownBy(breakdown, by));
                } else {
                    m.addAttribute("error", "authentication");
                    m.addAttribute("message",
                            "Please authenticate yourself with the ALA system with an administrator account");
                }

            } else {
                m.addAttribute("breakdown", actionDao.getActionBreakdownUserBy(useremail, breakdown, by));
            }
        }
    }

    return m;

}

From source file:com.forexnepal.controller.HomeController.java

@RequestMapping(value = "/exchange_rates/time/{time}", method = RequestMethod.GET)
public @ResponseBody ModelMap ExchangeRatesByTime(@PathVariable(value = "time") Time time) {
    ModelMap map = new ModelMap();
    map.addAttribute("exchangeRatesByTime", exchangeRatesService.getByTime(time));
    return map;/*from   w  w w  .j  a  v  a 2s  .  c om*/
}

From source file:cz.muni.fi.mir.controllers.SourceDocumentController.java

@Secured("ROLE_ADMINISTRATOR")
@SiteTitle("{entity.sourceDocument.edit}")
@RequestMapping(value = { "/edit", "/edit/" }, method = RequestMethod.POST)
public ModelAndView editSourceDocumentSubmit(
        @Valid @ModelAttribute("sourceDocumentForm") SourceDocumentForm sourceDocumentForm,
        BindingResult result, Model model) {
    if (result.hasErrors()) {
        ModelMap mm = new ModelMap();
        mm.addAttribute("sourceDocumentForm", sourceDocumentForm);
        mm.addAttribute(model);//from w ww .ja  va2  s . com

        return new ModelAndView("sourcedocument_edit", mm);
    } else {
        sourceDocumentService.updateSourceDocument(mapper.map(sourceDocumentForm, SourceDocument.class));

        return new ModelAndView("redirect:/sourcedocument/list/");
    }
}

From source file:org.agatom.springatom.cmp.wizards.data.context.WizardDataScopeHolder.java

@SuppressWarnings("unchecked")
private WizardDataScopeHolder addData(final DataScope scope, final String key, final Object data) {
    LOGGER.trace(/*from   w w  w.j  ava  2 s.  c o  m*/
            String.format("addData(scope=%s,key=%s,data=%s)", scope, key, ObjectUtils.getDisplayString(data)));
    if (data == null) {
        LOGGER.trace(String.format("Cannot add data, because it is null"));
        return this;
    } else if (ClassUtils.isAssignableValue(Collection.class, data) && ((Collection<?>) data).isEmpty()) {
        LOGGER.trace(String.format("Data is an empty collection, wont be added"));
        return this;
    } else if (ClassUtils.isAssignableValue(Map.class, data) && ((Map<?, ?>) data).isEmpty()) {
        LOGGER.trace(String.format("Data is an empty collection, wont be added"));
        return this;
    }
    ModelMap localHolder = this.data.get(scope);
    if (localHolder == null) {
        localHolder = new ModelMap();
        this.data.put(scope, localHolder);
    }

    final boolean isMap = ClassUtils.isAssignableValue(Map.class, data);
    final boolean isCollection = ClassUtils.isAssignableValue(Collection.class, data);
    final boolean keyHasText = StringUtils.hasText(key);

    if (isMap && !keyHasText) {
        localHolder.addAllAttributes((Map<String, ?>) data);
    } else if (isCollection && !keyHasText) {
        localHolder.addAllAttributes((Collection<?>) data);
    } else if (!keyHasText) {
        localHolder.addAttribute(data);
    } else {
        localHolder.addAttribute(key, data);
    }

    return this;
}

From source file:info.raack.appliancedetection.evaluation.web.BaseController.java

@ExceptionHandler
public ModelAndView handleUncaughtException(Exception ex, HttpServletRequest request,
        HttpServletResponse response) {//from   ww w.  ja v a  2  s. co  m

    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    errorService.reportError("Error", URGENCY.URGENT, ex);
    logger.error("An exception was caught while processing", ex);

    return new ModelAndView("error", new ModelMap());
}

From source file:com.forexnepal.controller.AdminController.java

@RequestMapping(value = "all_currency", method = RequestMethod.GET)
public @ResponseBody ModelMap allCurrency() {
    ModelMap mv = new ModelMap();

    mv.addAttribute("allCurrency", currencyService.getAll());

    return mv;/*from   w  ww.  j  a v a 2 s. c om*/
}

From source file:org.motechproject.server.omod.web.controller.MotechModuleFormControllerTest.java

public void testViewBlackoutFormNoData() throws ParseException {
    expect(contextService.getMotechService()).andReturn(motechService);
    expect(motechService.getBlackoutSettings()).andReturn(null);

    replay(contextService, motechService);

    ModelMap model = new ModelMap();
    String path = controller.viewBlackoutSettings(model);

    verify(contextService, motechService);

    assertEquals("/module/motechmodule/blackout", path);
}

From source file:fragment.web.AbstractConnectorControllerTest.java

@Before
public void init() throws Exception {
    map = new ModelMap();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
}

From source file:se.vgregion.portal.iframe.controller.CSViewControllerTest.java

@Test
public void testShowView_NoAuth() throws ReadOnlyException {
    PortletPreferences prefs = new MockPortletPreferences();
    initPortletPreferences(prefs);// w  ww. j a va2 s . co  m
    prefs.setValue("auth", "false");

    RenderRequest mockReq = new MockRenderRequest(PortletMode.VIEW);
    RenderResponse mockResp = new MockRenderResponse();
    ModelMap model = new ModelMap();

    String response = controller.showView(prefs, mockReq, mockResp, model);
    assertEquals("view", response);

    // Test model
    assertEquals("test-src", model.get("iFrameSrc"));
    assertEquals("test-src", model.get("baseSrc"));
    assertEquals("300", model.get("iFrameHeight"));
    assertEquals("0", model.get("border"));
    assertEquals("#000000", model.get("bordercolor"));
    assertEquals("0", model.get("frameborder"));
    assertEquals("600", model.get("height-maximized"));
    assertEquals("300", model.get("height-normal"));
    assertEquals("0", model.get("hspace"));
    assertEquals("auto", model.get("scrolling"));
    assertEquals("0", model.get("vspace"));
    assertEquals("100%", model.get("width"));
}

From source file:com.callcenter.controller.RecordingLibraryServiceControllerTest.java

@Test
public void shouldPopulateAllServicesInTheModelMap(
        final @NonStrict RecordingLibraryService recordingLibraryService) {
    final ArrayList<RecordingLibraryService> services = new ArrayList<RecordingLibraryService>();
    new NonStrictExpectations() {
        {/* ww w  .  ja va 2  s. co m*/
            RecordingLibraryService.findAllRecordingLibraryServices();
            returns(services);
        }
    };
    final ModelMap map = new ModelMap();
    controller.list(map);
    assertSame(services, map.get("services"));
}