Example usage for org.springframework.web.servlet ModelAndView getModel

List of usage examples for org.springframework.web.servlet ModelAndView getModel

Introduction

In this page you can find the example usage for org.springframework.web.servlet ModelAndView getModel.

Prototype

public Map<String, Object> getModel() 

Source Link

Document

Return the model map.

Usage

From source file:com.exxonmobile.ace.hybris.storefront.interceptors.beforeview.SeoRobotsFollowBeforeViewHandler.java

@Override
public void beforeView(final HttpServletRequest request, final HttpServletResponse response,
        final ModelAndView modelAndView) {
    // Check to see if the controller has specified a Index/Follow directive for robots
    if (modelAndView != null && !modelAndView.getModel().containsKey("metaRobots")) {
        // Build a default directive
        String robotsValue = "no-index,no-follow";

        if (RequestMethod.GET.name().equalsIgnoreCase(request.getMethod())) {
            if (request.isSecure()) {
                robotsValue = "no-index,follow";
            }//from ww  w.  j ava2s.  co  m
            //Since no model attribute metaRobots can be set for JSON response, then configure that servlet path in the xml.
            //If its a regular response and this setting has to be overriden then set model attribute metaRobots
            else if (CollectionUtils.contains(getRobotIndexForJSONMapping().keySet().iterator(),
                    request.getServletPath())) {
                robotsValue = getRobotIndexForJSONMapping().get(request.getServletPath());
            } else {
                robotsValue = "index,follow";
            }
        } else if (RequestMethod.POST.name().equalsIgnoreCase(request.getMethod())) {
            robotsValue = "no-index,no-follow";
        }

        modelAndView.addObject("metaRobots", robotsValue);

    }

    if (modelAndView != null && modelAndView.getModel().containsKey("metatags")) {
        final MetaElementData metaElement = new MetaElementData();
        metaElement.setName("robots");
        metaElement.setContent((String) modelAndView.getModel().get("metaRobots"));
        ((List<MetaElementData>) modelAndView.getModel().get("metatags")).add(metaElement);
    }
}

From source file:org.sventon.web.ctrl.template.ListFilesController.java

@Override
protected ModelAndView svnHandle(final SVNConnection connection, final BaseCommand command,
        final long headRevision, final UserRepositoryContext userRepositoryContext,
        final HttpServletRequest request, final HttpServletResponse response, final BindException exception)
        throws Exception {

    final ModelAndView modelAndView = super.svnHandle(connection, command, headRevision, userRepositoryContext,
            request, response, exception);

    final Map<String, Object> model = modelAndView.getModel();
    final List<DirEntry> entries = (List<DirEntry>) model.get("dirEntries");
    final DirEntryKindFilter entryFilter = new DirEntryKindFilter(DirEntry.Kind.FILE);
    final int rowNumber = ServletRequestUtils.getRequiredIntParameter(request, "rowNumber");

    logger.debug("Adding data to model");
    model.put("dirEntries", entryFilter.filter(entries));
    model.put("rowNumber", rowNumber);
    modelAndView.setViewName(getViewName());
    return modelAndView;
}

From source file:jetbrains.buildServer.clouds.azure.web.AzureEditProfileController.java

@Override
protected ModelAndView doGet(final HttpServletRequest request, final HttpServletResponse response) {
    ModelAndView mv = new ModelAndView(myJspPath);
    mv.getModel().put("refreshablePath", myHtmlPath);
    mv.getModel().put("resPath", myPluginDescriptor.getPluginResourcesPath());
    return mv;// w w  w  . ja va2  s. co m
}

From source file:org.openmrs.module.openhmis.inventory.web.controller.InventoryMessageRenderController.java

@RequestMapping(method = RequestMethod.GET)
public ModelAndView render(HttpServletRequest request) {
    // object to store keys from inventory and backboneforms
    Vector<String> keys = new Vector<String>();

    Locale locale = RequestContextUtils.getLocale(request);
    ResourceBundle resourceBundle = ResourceBundle.getBundle("messages", locale);

    // store inventory message keys in the vector object
    keys.addAll(resourceBundle.keySet());

    // retrieve backboneforms messages
    BackboneMessageRenderController backboneController = new BackboneMessageRenderController();
    ModelAndView modelAndView = backboneController.render(request);

    // store backboneforms message keys in the vector object
    for (Map.Entry<String, Object> messageKeys : modelAndView.getModel().entrySet()) {
        Enumeration<String> messageKey = (Enumeration<String>) messageKeys.getValue();
        while (messageKey.hasMoreElements()) {
            String key = messageKey.nextElement();
            if (!keys.contains(key))
                keys.add(key);//from   w  ww  .  j  a  v  a2  s.c o  m
        }
    }

    return new ModelAndView(ModuleWebConstants.MESSAGE_PAGE, "keys", keys.elements());
}

From source file:com.carlos.projects.billing.ui.controllers.ImportComponentsControllerTest.java

@Test
public void shouldImportDataAndPutNumberOfImportedItemsInTheModelWhenOnSubmit() throws Exception {
    //given/*from w  ww.  j  a v a2s.co  m*/
    ImportComponentsController controller = new ImportComponentsController(importer, componentDAO);
    List<Component> components = createComponents();
    Map<String, Object> expectedModel = mockExpectedModel(components);
    when(command.getFile()).thenReturn(file);
    when(importer.importData(file)).thenReturn(2L);
    when(componentDAO.findAll("Component")).thenReturn(components);

    //when
    ModelAndView mav = controller.onSubmit(command);

    //then
    assertThat(mav.getViewName(), is("showComponents"));
    assertThat(mav.getModel(), is(expectedModel));
}

From source file:de.otto.jsonhome.controller.HtmlControllerTest.java

@Test
public void testGetRel() throws Exception {
    // given/*  w  w  w. j a  v a 2  s.  c o  m*/
    final HtmlController controller = relController(
            ControllerWithRequestMappingAndLinkRelationTypeAtClassLevel.class);
    // when
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/rel/foo");
    request.setServerName("rel.example.org");
    request.setScheme("http");
    final ModelAndView resourcesMap = controller.getRelationshipType(request);
    // then
    assertEquals(resourcesMap.getViewName(), "directresource");
    assertNotNull(resourcesMap.getModel().get("resource"));
    @SuppressWarnings("unchecked")
    final DirectLink model = (DirectLink) resourcesMap.getModel().get("resource");
    assertEquals(model.getHref(), URI.create("http://app.example.org/bar"));
}

From source file:org.openmrs.module.openhmis.cashier.web.controller.CashierMessageRenderController.java

@RequestMapping(method = RequestMethod.GET)
public ModelAndView render(HttpServletRequest request) {
    // object to store keys from cashier and backboneforms
    Vector<String> keys = new Vector<String>();

    // locate and retrieve cashier messages
    Locale locale = RequestContextUtils.getLocale(request);
    ResourceBundle resourceBundle = ResourceBundle.getBundle("messages", locale);

    // store cashier message keys in the vector object
    keys.addAll(resourceBundle.keySet());

    // retrieve backboneforms messages
    BackboneMessageRenderController backboneController = new BackboneMessageRenderController();
    ModelAndView modelAndView = backboneController.render(request);

    // store backboneforms message keys in the vector object
    for (Map.Entry<String, Object> messageKeys : modelAndView.getModel().entrySet()) {
        Enumeration<String> messageKey = (Enumeration<String>) messageKeys.getValue();
        while (messageKey.hasMoreElements()) {
            String key = messageKey.nextElement();
            if (!keys.contains(key))
                keys.add(key);/*  w  ww  .  ja v  a  2  s  .c  om*/
        }
    }

    return new ModelAndView(CashierWebConstants.MESSAGE_PAGE, "keys", keys.elements());
}

From source file:com.ge.predix.acs.commons.web.RestErrorHandlerTest.java

private void assertRestApiErrorResponse(final ModelAndView errorResponse, final String code,
        final String message) {
    RestApiErrorResponse restApiErrorResponse = (RestApiErrorResponse) errorResponse.getModel()
            .get("ErrorDetails");

    Assert.assertEquals(restApiErrorResponse.getErrorCode(), code);

    Assert.assertEquals(restApiErrorResponse.getErrorMessage(), message);
}

From source file:com.carlos.projects.billing.ui.controllers.LoadComponentsControllerTest.java

@Test
public void shouldNotAddDocumentIdToModelIfItIsPresentOnRequestButItIsNotNumeric() throws Exception {
    //Given//  www . j a  v a 2  s .  c o m
    String documentId = "123a";
    when(request.getParameter("documentId")).thenReturn(documentId);

    //When
    ModelAndView modelAndView = controller.handleRequest(request, response);

    //Then
    assertThat("The document id is wrong", modelAndView.getModel().get("documentId"), is(nullValue()));
}

From source file:ru.org.linux.user.EditRemarkController.java

@RequestMapping(method = RequestMethod.GET)
public ModelAndView showForm(ServletRequest request, @PathVariable String nick) throws Exception {
    Template tmpl = Template.getTemplate(request);

    if (!tmpl.isSessionAuthorized()) {
        throw new AccessViolationException("Not authorized");
    }//from  w  ww .  ja v a 2s  .co m

    ModelAndView mv = new ModelAndView("edit-remark");

    User user = userDao.getUser(nick);
    if (tmpl.isSessionAuthorized() && !tmpl.getNick().equals(nick)) {
        mv.getModel().put("remark", userDao.getRemark(tmpl.getCurrentUser(), user));
    } else {
        throw new AccessViolationException("Not Authorized");
    }
    return mv;
}