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

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

Introduction

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

Prototype

public void setView(@Nullable View view) 

Source Link

Document

Set a View object for this ModelAndView.

Usage

From source file:com.mmj.app.web.controller.cms.CMSController.java

@RequestMapping(value = "/link/cityCode.do")
public ModelAndView cityCode(Integer parentId) {
    ModelAndView mav = new ModelAndView();
    mav.setView(new MappingJackson2JsonView());
    if (parentId == null || parentId < 0) {
        mav.addObject("code", 0000);
        mav.addObject("data", Collections.emptyList());
        return mav;
    }/*from   w  ww.ja v  a  2 s  .co  m*/
    mav.addObject("code", 9999);
    mav.addObject("data", CityUtils.getCityById(parentId));
    return mav;
}

From source file:gov.nih.nci.calims2.ui.report.filledreport.FilledReportController.java

/**
 * @return model The ModelAndView returned.
 *///from  w w  w  .j av a2  s  .  com
@RequestMapping("/runReport.do")
public ModelAndView runReport() {
    Long id = (Long) (FlowContextHolder.getContext().peek()).getAttribute("id");
    try {
        ((FilledReportService) getMainService()).createFilledReport(id, tempfiledir);
    } catch (ReportingException e) {
        throw new RuntimeException("Reporting exception", e);
    }
    ModelAndView model = new ModelAndView();
    CRUDControllerConfig config = getConfig();
    model.setView(new RedirectView(config.getForwardUrl(config.getListCommand()), true));
    model.addObject(FlowContextInterceptor.CONTEXT_PARAM, FlowContextHolder.setPersistAttributeForClient(this));
    return model;
}

From source file:org.openmrs.module.pmtct.web.controller.UpdatePatientInformationController.java

/**
 * @see org.springframework.web.servlet.mvc.ParameterizableViewController#handleRequestInternal(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *//*from   w w w.  ja  va  2 s.co  m*/
@SuppressWarnings({ "deprecation" })
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    if (Context.getAuthenticatedUser() == null)
        return new ModelAndView(new RedirectView(request.getContextPath() + "/login.htm"));

    Patient p = null;

    ModelAndView mav = new ModelAndView();
    mav.setView(new RedirectView(getViewName() + "?patientId=" + request.getParameter("patientId")));

    try {

        //         config = PMTCTConfiguration.getInstance(request.getRealPath(PMTCTConstants.CONFIGURATION_FILE_LOC));
        //         request.getSession().setAttribute("enableModification", "" + config.isModificationEnabled());
        //         constants = config.getConstants();

        request.getSession().setAttribute("pmtctModuleConfigured", "" + PMTCTConfigurationUtils.isConfigured());

        p = Context.getPatientService().getPatient(Integer.parseInt(request.getParameter("patientId")));
        //         PersonService ps = Context.getPersonService();
        //BIRTHDATE_ATTRIBUTE
        //p.setBirthdate(Context.getDateFormat().parse(request.getParameter("birthdate")));
        //p.setGender(request.getParameter("addGender"));

        if (request.getParameter("formAttribute") != null)
            p = updatePersonAttributes(request, p);
        //         if (request.getParameter("formAddress") != null)
        //            p = updatePersonAddress(request, p);

        //saving the changes
        Context.getPatientService().updatePatient(p);

        log.info("Information updated successifully for patient with id " + request.getParameter("patientId"));

        String msg = getMessageSourceAccessor().getMessage("pmtct.general.saveSuccess");
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, msg);

        //refreshing the patient object
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("patient", p);
        //         model.put("location", p.getPersonAddress());

        //         request.getSession().setAttribute("model", model);

        //         because the gender cant be updated from here, no need to check if the patient is male
        //         if(p.getGender().compareToIgnoreCase("M")==0)
        //            mav.setView(new RedirectView(request.getContextPath()+"/patientDashboard.form?patientId=" + request.getParameter("patientId")));

    } catch (Exception e) {
        log.error("An error occured when trying to update information for patient with id "
                + request.getParameter("patientId"));
        e.printStackTrace();

        String msg = getMessageSourceAccessor().getMessage("pmtct.general.notSaved");
        request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, msg);

    }

    return mav;
}

From source file:com.wiiyaya.consumer.web.main.controller.ExceptionController.java

private ModelAndView prepareExceptionInfo(HttpServletRequest request, HttpStatus httpStatus, String errorCode,
        String errorMessage) {/*  w  ww. j a v  a2s .  c  o m*/
    Map<String, Object> models = new LinkedHashMap<>();
    models.put("statusCode", httpStatus.value());
    models.put("errorCode", errorCode);
    models.put("errorMessage", errorMessage);
    ModelAndView modelAndView = new ModelAndView();
    if (noNeedWrapper(request)) {
        modelAndView.setView(DEFAULT_JSON_VIEW);
        modelAndView.addAllObjects(models);
        return modelAndView;
    } else {
        modelAndView.setViewName("error");
        modelAndView.addAllObjects(models);
        return modelAndView;
    }
}

From source file:com.mmj.app.web.controller.BaseController.java

@Override
protected ModelAndView createJsonMav(String msg, ResultCode code, Object object) {
    ModelAndView mav = new ModelAndView();
    mav.setView(new MappingJackson2JsonView());
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("code", Integer.toString(code.value));
    map.put("message", msg);
    map.put("data", object == null ? StringUtils.EMPTY : object);
    mav.addObject("result", map);
    return mav;/*from w ww  .j a v  a 2  s  . com*/
}

From source file:com.fengduo.bee.web.controller.product.ItemController.java

private ModelAndView createJsonMav(boolean isSuccess, Long code, String info) {
    ModelAndView mav = new ModelAndView();
    mav.setView(new MappingJackson2JsonView());
    mav.addObject("isSuccess", isSuccess);
    mav.addObject("code", code);
    mav.addObject("info", info);
    return mav;/*  ww w.  j  ava2 s.  c  o m*/
}

From source file:tv.arte.resteventapi.web.errors.GlobalDefaultExceptionHandler.java

/**
 * Handle all exceptions of type {@link ImageRepositoryException} thrown by (or passing trough) the Controller's layer
 * /*from w w w .j  a  va  2 s.co  m*/
 * @param response The HttpServletResponse
 * @param e Thrown NoResultInApiException
 * @return
 * @throws Exception
 */
@ExceptionHandler(value = NoResultInApiException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public ModelAndView noResultInApiExceptionHandler(HttpServletResponse response, NoResultInApiException e)
        throws Exception {
    if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
        throw e;
    }

    RestEventApiStandardResponse<RestEventApiMessage> restEventApiStandardResponse = new RestEventApiStandardResponse<RestEventApiMessage>();
    restEventApiStandardResponse.addError(RestEventApiError.PRE_DEFINED.RIA_ERR_G_SEARCH_NO_RESULTS);

    ModelAndView mav = new ModelAndView();
    mav.addObject(restEventApiStandardResponse);
    mav.setView(restEventApiDefaultErrorView);

    return mav;
}

From source file:tv.arte.resteventapi.web.errors.GlobalDefaultExceptionHandler.java

/**
 * Handle all exceptions thrown by Controller's layer and that have not been already handled
 * //from   www  . j av a  2s .c  om
 * @param response The HttpServletResponse
 * @param e Thrown exception
 * @return
 * @throws Exception
 */
@ExceptionHandler(value = Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView defaultErrorHandler(HttpServletResponse response, Exception e) throws Exception {
    if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
        throw e;
    }

    RestEventApiStandardResponse<RestEventApiMessage> restEventApiStandardResponse = new RestEventApiStandardResponse<RestEventApiMessage>();
    restEventApiStandardResponse.addError(RestEventApiError.PRE_DEFINED.RIA_ERR_G_UNKNOWN);

    if (e instanceof NullPointerException) {
        //Log full stacktrace in case of NullPointer
        logger.error(ExceptionUtils.getFullStackTrace(e));
    }

    ModelAndView mav = new ModelAndView();
    mav.addObject(restEventApiStandardResponse);
    mav.setView(restEventApiDefaultErrorView);

    return mav;
}

From source file:net.indialend.attendance.controller.IndexController.java

@RequestMapping(value = "/index", method = RequestMethod.GET)
public ModelAndView login(@RequestParam(value = "error", required = false) String error,
        @RequestParam(value = "logout", required = false) String logout, Principal principal) {

    ModelAndView model = new ModelAndView("index");

    if (error != null) {
        model.addObject("error", "Invalid username and password!");
    }//from  ww  w .  j a v a  2  s  .  c o m

    if (logout != null) {
        model.addObject("msg", "You've been logged out successfully.");
    }

    if (principal != null) {
        model.setView(new RedirectView("branch/list"));
    }
    return model;

}

From source file:tv.arte.resteventapi.web.errors.GlobalDefaultExceptionHandler.java

/**
 * Handle all exceptions of type {@link ImageRepositoryException} thrown by (or passing trough) the Controller's layer
 * /*w  ww .  jav a2  s.  com*/
 * @param response The HttpServletResponse
 * @param e Thrown RestEventApiValidationException
 * @return
 * @throws Exception
 */
@SuppressWarnings("unchecked")
@ExceptionHandler(value = RestEventApiValidationException.class)
public ModelAndView restEventApiValidationExceptionHandler(HttpServletResponse response,
        RestEventApiValidationException e) throws Exception {
    if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
        throw e;
    }

    RestEventApiStandardResponse<RestEventApiMessage> restEventApiStandardResponse = new RestEventApiStandardResponse<RestEventApiMessage>();
    restEventApiStandardResponse
            .setErrors((Collection<RestEventApiMessage>) (Collection<?>) e.getValidationErrorMessages());

    ModelAndView mav = new ModelAndView();
    mav.addObject(restEventApiStandardResponse);
    mav.setView(restEventApiDefaultErrorView);

    if (e.getResponseHttpStatusCode() != null) {
        response.setStatus(e.getResponseHttpStatusCode());
    } else {
        response.setStatus(HttpStatus.BAD_REQUEST.value());
    }

    return mav;
}