Search in sources :

Example 26 with ModelMap

use of org.springframework.ui.ModelMap in project jstorm by alibaba.

the class FilesController method show.

@RequestMapping(value = "/files", method = RequestMethod.GET)
public String show(@RequestParam(value = "cluster", required = true) String cluster_name, @RequestParam(value = "host", required = true) String host, @RequestParam(value = "port", required = false) String port, @RequestParam(value = "dir", required = false) String dir, ModelMap model) {
    cluster_name = StringEscapeUtils.escapeHtml(cluster_name);
    dirs.clear();
    files.clear();
    Map conf = UIUtils.readUiConfig();
    if (StringUtils.isBlank(dir)) {
        dir = ".";
    }
    String[] path = dir.split("/");
    model.addAttribute("path", path);
    int i_port;
    if (StringUtils.isBlank(port)) {
        i_port = ConfigExtension.getNimbusDeamonHttpserverPort(conf);
    } else {
        i_port = JStormUtils.parseInt(port);
    }
    //proxy request for files info
    String summary = requestFiles(host, i_port, dir);
    model.addAttribute("summary", summary);
    model.addAttribute("files", files);
    model.addAttribute("dirs", dirs);
    // status save
    model.addAttribute("clusterName", cluster_name);
    model.addAttribute("host", host);
    model.addAttribute("port", i_port);
    model.addAttribute("parent", dir);
    UIUtils.addTitleAttribute(model, "Files");
    return "files";
}
Also used : ModelMap(org.springframework.ui.ModelMap) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with ModelMap

use of org.springframework.ui.ModelMap in project head by mifos.

the class ApprovalRESTController method reject.

@RequestMapping(value = "id-{id}/reject", method = RequestMethod.POST)
public ModelMap reject(@PathVariable(value = "id") Long id) throws Exception {
    ModelMap model = new ModelMap();
    approvalService.reject(id);
    model.addAttribute("status", "success");
    return model;
}
Also used : ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with ModelMap

use of org.springframework.ui.ModelMap in project head by mifos.

the class ApprovalRESTController method approve.

@RequestMapping(value = "id-{id}/approve", method = RequestMethod.POST)
public ModelMap approve(@PathVariable(value = "id") Long id) throws Exception {
    ModelMap model = new ModelMap();
    Object result = approvalService.approve(id);
    if (result.toString().startsWith("Error")) {
        model.addAttribute("status", "error");
    } else {
        model.addAttribute("status", "success");
    }
    model.addAttribute("result", result);
    return model;
}
Also used : ModelMap(org.springframework.ui.ModelMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with ModelMap

use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.

the class RedirectAttributesMethodArgumentResolver method resolveArgument.

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    ModelMap redirectAttributes;
    if (binderFactory != null) {
        DataBinder dataBinder = binderFactory.createBinder(webRequest, null, null);
        redirectAttributes = new RedirectAttributesModelMap(dataBinder);
    } else {
        redirectAttributes = new RedirectAttributesModelMap();
    }
    mavContainer.setRedirectModel(redirectAttributes);
    return redirectAttributes;
}
Also used : RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) ModelMap(org.springframework.ui.ModelMap) DataBinder(org.springframework.validation.DataBinder) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)

Example 30 with ModelMap

use of org.springframework.ui.ModelMap in project spring-framework by spring-projects.

the class ExceptionHandlerExceptionResolver method doResolveHandlerMethodException.

/**
	 * Find an {@code @ExceptionHandler} method and invoke it to handle the raised exception.
	 */
@Override
protected ModelAndView doResolveHandlerMethodException(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, Exception exception) {
    ServletInvocableHandlerMethod exceptionHandlerMethod = getExceptionHandlerMethod(handlerMethod, exception);
    if (exceptionHandlerMethod == null) {
        return null;
    }
    exceptionHandlerMethod.setHandlerMethodArgumentResolvers(this.argumentResolvers);
    exceptionHandlerMethod.setHandlerMethodReturnValueHandlers(this.returnValueHandlers);
    ServletWebRequest webRequest = new ServletWebRequest(request, response);
    ModelAndViewContainer mavContainer = new ModelAndViewContainer();
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Invoking @ExceptionHandler method: " + exceptionHandlerMethod);
        }
        Throwable cause = exception.getCause();
        if (cause != null) {
            // Expose cause as provided argument as well
            exceptionHandlerMethod.invokeAndHandle(webRequest, mavContainer, exception, cause, handlerMethod);
        } else {
            // Otherwise, just the given exception as-is
            exceptionHandlerMethod.invokeAndHandle(webRequest, mavContainer, exception, handlerMethod);
        }
    } catch (Throwable invocationEx) {
        // probably an accident (e.g. failed assertion or the like).
        if (invocationEx != exception && logger.isWarnEnabled()) {
            logger.warn("Failed to invoke @ExceptionHandler method: " + exceptionHandlerMethod, invocationEx);
        }
        // Continue with default processing of the original exception...
        return null;
    }
    if (mavContainer.isRequestHandled()) {
        return new ModelAndView();
    } else {
        ModelMap model = mavContainer.getModel();
        HttpStatus status = mavContainer.getStatus();
        ModelAndView mav = new ModelAndView(mavContainer.getViewName(), model, status);
        mav.setViewName(mavContainer.getViewName());
        if (!mavContainer.isViewReference()) {
            mav.setView((View) mavContainer.getView());
        }
        if (model instanceof RedirectAttributes) {
            Map<String, ?> flashAttributes = ((RedirectAttributes) model).getFlashAttributes();
            request = webRequest.getNativeRequest(HttpServletRequest.class);
            RequestContextUtils.getOutputFlashMap(request).putAll(flashAttributes);
        }
        return mav;
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) HttpStatus(org.springframework.http.HttpStatus) ModelMap(org.springframework.ui.ModelMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest)

Aggregations

ModelMap (org.springframework.ui.ModelMap)48 Test (org.junit.Test)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 ModelAndView (org.springframework.web.servlet.ModelAndView)11 RedirectAttributesModelMap (org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)5 Map (java.util.Map)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 IOException (java.io.IOException)3 Date (java.util.Date)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 HttpSessionRequiredException (org.springframework.web.HttpSessionRequiredException)3 RedirectAttributes (org.springframework.web.servlet.mvc.support.RedirectAttributes)3 NimbusClient (backtype.storm.utils.NimbusClient)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2