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:demo.oauth.server.controllers.ApplicationController.java

@RequestMapping("/registerClient")
public ModelAndView registerApp(@ModelAttribute("client") ClientApp clientApp) throws Exception {

    if (StringUtils.isEmpty(clientApp.getClientName())) {
        clientApp.setError("Client name field is required!");

        return handleInternalRedirect(clientApp);
    }/*from   w  ww. j  av  a2  s.c  o  m*/

    MD5SequenceGenerator tokenGen = new MD5SequenceGenerator();
    Principal principal = SecurityContextHolder.getContext().getAuthentication();
    String consumerKey = clientApp.getConsumerKey();
    if (StringUtils.isEmpty(consumerKey)) {
        consumerKey = tokenGen
                .generate((principal.getName() + clientApp.getClientName()).getBytes(StandardCharsets.UTF_8));
    }

    String secretKey = tokenGen.generate(new SecureRandom().generateSeed(20));

    Client clientInfo = new Client(consumerKey, secretKey, clientApp.getClientName(), null);
    clientInfo.setCallbackURI(clientApp.getCallbackURL());
    clientInfo.setLoginName(principal.getName());

    Client authNInfo = clientManager.registerNewClient(consumerKey, clientInfo);
    if (authNInfo != null) {
        clientApp.setError("Client already exists!");

        return handleInternalRedirect(clientApp);
    }

    ModelAndView modelAndView = new ModelAndView("clientDetails");
    modelAndView.getModel().put("clientInfo", clientInfo);

    return modelAndView;
}

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

@Test
public void shouldNotAddDocumentIdToModelIfItIsPresentOnRequestButIsNotNumeric() throws Exception {
    //given/*from   ww  w  . j a v  a 2 s.c om*/
    String documentId = "123a";
    when(request.getParameter("documentId")).thenReturn(documentId);

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

    //then
    assertThat("Document id is not correct", modelAndView.getModel().get("documentId"), is(nullValue()));
}

From source file:debrepo.teamcity.web.DebRepoListingPageController.java

@Override
protected ModelAndView doHandle(HttpServletRequest request, HttpServletResponse response) {

    List<DebRepositoryConfigProjectAndStatsWrapper> reposList = getReposList();
    ModelAndView mv = new ModelAndView(
            myPluginDescriptor.getPluginResourcesPath("debRepository/debianRepositories.jsp"));
    mv.getModel().put("repoConfigs", reposList);
    return mv;//from   ww  w  . j a  v a  2  s  . com
}

From source file:com.formkiq.core.controller.user.DesignerController.java

/**
 * User Workflow Edit page.//from  w  ww.  java 2s . c om
 * @param request {@link HttpServletRequest}
 * @return {@link ModelAndView}
 * @throws Exception Exception
 */
@Transactional
@RequestMapping(value = { "/edit" }, method = RequestMethod.POST)
public ModelAndView editPost(final HttpServletRequest request) throws Exception {
    // TODO test..

    try {
        Object result = this.flowEventService.processRequest(request);
        if (result != null && result instanceof ModelAndView) {
            ModelAndView mav = (ModelAndView) result;
            if (!mav.getModel().containsKey("flow")) {
                return mav;
            }
        }
    } catch (FlowEventMethodNotFound e) {
        // ignore
        // TODO remove...
    }

    String view = "redirect:/user/dashboard";
    Map<String, String> errors = this.workflowEditService.save(request);

    if (!errors.isEmpty()) {
        view = "redirect:" + request.getRequestURI() + "?" + request.getQueryString();
    }

    return new ModelAndView(view);
}

From source file:org.guanxi.sp.engine.form.RegisterIdPFormController.java

@SuppressWarnings("unchecked")
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws Exception {
    File newIdPFile = new File(config.getIdPMetadataDirectory(), request.getParameter("filename") + ".xml");
    createIdPFile(newIdPFile, request.getParameter("entityID"), request.getParameter("aa"),
            request.getParameter("x509").replaceAll("\r", ""));

    EntityDescriptorDocument loadedIdPDocument = EntityDescriptorDocument.Factory.parse(newIdPFile);

    EntityFarm farm = (EntityFarm) config.getServletContext()
            .getAttribute(Guanxi.CONTEXT_ATTR_ENGINE_ENTITY_FARM);
    // The source is defined in config/spring/application/entity.xml
    EntityManager manager = farm.getEntityManagerForSource("local-metadata");
    Metadata metadataHandler = manager.createNewEntityHandler();
    metadataHandler.setPrivateData(loadedIdPDocument.getEntityDescriptor());
    manager.addMetadata(metadataHandler);

    ModelAndView mAndV = new ModelAndView();
    mAndV.setViewName(getSuccessView());
    mAndV.getModel().put("message",
            messageSource.getMessage("register.idp.success.message", null, request.getLocale()));
    return mAndV;
}

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

@Test
public void shouldAddDocumentIdToModelIfItIsPresentOnRequest() throws Exception {
    //given/* w  w w.ja  v  a2  s  . c  o  m*/
    Long documentId = 123L;
    when(request.getParameter("documentId")).thenReturn(documentId.toString());

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

    //then
    assertThat("Document id is not correct", (Long) modelAndView.getModel().get("documentId"), is(documentId));
}

From source file:com.mmj.app.web.controller.upload.FileUploadController.java

@RequestMapping(value = "/link/pic/upload")
public ModelAndView picUpload(String identifie, @RequestParam("imgUrl") MultipartFile... files) {
    ModelAndView mav = new ModelAndView("return");
    mav.getModel().put(CustomVelocityLayoutView.USE_LAYOUT, "false");

    if (files == null || files.length <= 0) {
        return returnErrorJson(mav);
    }/*from   w w w.j  a va  2  s . co m*/
    List<String> urlList = new ArrayList<String>();
    for (int i = 0; i < files.length; i++) {
        Result result = fileService.createFilePath(files[i]);
        if (result == null || result.getData() == null) {
            return returnErrorJson(mav);
        }
        urlList.add((String) result.getData());
    }
    String imgUrl = urlList.get(0);
    String[] urlArray = StringUtils.split(imgUrl, ".");
    imgUrl = urlArray[0] + "=420x185" + "." + urlArray[1];
    logger.error("FileUploadController : picUpload url:" + imgUrl);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("result", new DefaultJsonResult(9999, "?", new ImgVO(imgUrl, identifie)));
    mav.addObject("json", new Gson().toJson(map));
    return mav;
}

From source file:nl.surfnet.coin.selfservice.control.HomeControllerTest.java

@Test
public void testAddsOfferedServicesToModel() throws Exception {
    ArrayList<OfferedService> expected = new ArrayList<>();
    when(csa.findOfferedServicesFor("id")).thenReturn(expected);

    ModelAndView modelAndView = controller.idp(request);
    assertEquals("idp", modelAndView.getViewName());
    assertTrue(modelAndView.getModel().containsKey("offeredServicePresenter"));
}

From source file:com.formkiq.core.controller.user.DesignerController.java

/**
 * User Workflow Edit page./*  w  ww.  j a v  a 2s . c  om*/
 * @param request {@link HttpServletRequest}
 * @param response {@link HttpServletResponse}
 * @param execution {@link String}
 * @return {@link ModelAndView}
 * @throws Exception Exception
 */
@RequestMapping(value = { "/edit" }, method = RequestMethod.GET)
public ModelAndView edit(final HttpServletRequest request, final HttpServletResponse response,
        final @RequestParam(name = "execution", required = false) String execution) throws Exception {

    WebFlow flow = FlowManager.get(request);

    this.flowEventService.processGetRequest(flow, request);

    try {
        Object result = this.flowEventService.processRequest(request);

        if (result != null && result instanceof ModelAndView) {
            ModelAndView mav = (ModelAndView) result;
            if (!mav.getModel().containsKey("flow")) {
                return mav;
            }
        }
    } catch (FlowEventMethodNotFound e) {
        // ignore
    }

    if (!flow.getSessionKey().equals(execution)) {

        Pair<String, Integer> split = FlowManager.getExecutionSessionKey(execution);

        Integer eventId = split.getRight();
        if (eventId != null) {
            flow.setEventId(eventId.intValue());
        }
    }

    return new ModelAndView("user/designer/edit", "flow", flow);
}

From source file:org.statefulj.webapp.controller.UserController.java

@ExceptionHandler(DuplicateUserException.class)
public ModelAndView handleError(DuplicateUserException e) {
    ModelAndView mv = new ModelAndView();
    mv.getModel().put("message", "Ooops... That User is already registered.  Try a different email");
    mv.getModel().put("reg", new RegistrationForm());
    return mv;//from  w w w.  j a v a2 s . c  o  m
}