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

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

Introduction

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

Prototype

public ModelAndView addAllObjects(@Nullable Map<String, ?> modelMap) 

Source Link

Document

Add all attributes contained in the provided Map to the model.

Usage

From source file:com.itjenny.web.ArticleController.java

@RequestMapping(value = "{title}", method = RequestMethod.POST)
public ModelAndView save(@PathVariable String title, @RequestParam String content) {
    ModelAndView mav = new ModelAndView();
    ModelMap model = new ModelMap();
    Article article = new Article();
    article.setTitle(title);/* w w  w  .j  ava 2s.  c o m*/
    article.setContent(content);
    article.setUserId(StringUtils.EMPTY);
    article.setPublished(true);
    articleService.save(article);
    mav.setViewName(View.ARTICLE);
    mav.addAllObjects(model);
    return new ModelAndView(new RedirectView(URL.makeAbsolutePath(URL.ARTICLE, title)));
}

From source file:gemlite.core.webapp.settings.ImportDbConfigController.java

@RequestMapping(value = "/import-db-config", method = RequestMethod.GET)
public ModelAndView add(ModelAndView modelAndView) {
    modelAndView = new ModelAndView(PAGE_PREFIX + "import-db-config");

    ConfigService service = JpaContext.getService(ConfigService.class);
    Map<String, String> map = service.getConfig(ConfigTypes.importdbconfig.getValue());
    if (map != null) {
        //psw//from   www  . j  a v a 2 s .com
        String psw = map.get(ConfigKeys.import_dbpsw.getValue());
        map.put(ConfigKeys.import_dbpsw.getValue(), DESUtil.decrypt(psw));
        modelAndView.addAllObjects(map);
    }
    return modelAndView;
}

From source file:de.interseroh.report.controller.ReportController.java

private void showReportForm(@PathVariable("reportName") String reportName,
        @ModelAttribute("parameterForm") ParameterForm form, ModelAndView modelAndView) {
    RedirectView redirectView = new RedirectView();
    redirectView.setUrl("/reports/{reportName}");
    redirectView.setContextRelative(true);
    redirectView.setPropagateQueryParams(false);
    redirectView.setExposeModelAttributes(true);
    modelAndView.addAllObjects(new ParameterValueMapBuilder().build(form));
    modelAndView.addObject("reportName", reportName);
    modelAndView.setView(redirectView);//  www  .j a v a  2 s  .co  m
}

From source file:gemlite.core.webapp.tools.DataModelController.java

@RequestMapping(value = "/model", method = RequestMethod.GET)
public ModelAndView model() {
    ModelAndView modelAndView = new ModelAndView("tools/data_model");

    DataModelService service = JpaContext.getService(DataModelService.class);
    List<DataModelConf> confList = service.findAll();
    if (confList != null && confList.size() > 0) {
        DataModelConf conf = confList.get(0);
        String pwd = conf.getPwd();
        conf.setPwd(DESUtil.decrypt(pwd));
        HashMap<String, String> map = getValueMap(conf);
        modelAndView.addAllObjects(map);
    }/*from w  ww. j a v  a 2  s.  c  o m*/
    return modelAndView;
}

From source file:no.dusken.aranea.web.spring.ChainedController.java

/**
 * Calls the handleRequest controller for each of the Controllers in the
 * chain sequentially, merging the ModelAndView objects returned after each
 * call and returning the merged ModelAndView object. An exception thrown by
 * any of the controllers in the chain will propagate upwards through the
 * handleRequest() method of the ChainedController. The ChainedController
 * itself does not support any communication between the controllers in the
 * chain, but this can be effected by the controllers posting to a common
 * accessible object such as the ApplicationContext. Note that this will
 * introduce coupling between the controllers and will be difficult to
 * arrange into a parallel chain. A controller can stop processing of the
 * chain by returning a null ModelAndView object. Enhanced with adding the
 * chained views to the controller. This enables the controller to render
 * the views from the chained controllers.
 *
 * @param request  the HttpServletRequest object.
 * @param response the HttpServletResponse object.
 * @return the merged ModelAndView object for all the controllers.
 * @throws Exception if one is thrown by one of the controllers in the chain.
 *//*from  w w w.  j a  v a  2  s.co  m*/
public ModelAndView handleRequestSequentially(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    ModelAndView mergedModel = new ModelAndView();
    List<String> mergedViews = new ArrayList<String>();
    for (Controller controller : controllers) {
        try {
            ModelAndView model = controller.handleRequest(request, response);
            if (model == null) {
                // chain will stop if a controller returns a null
                // ModelAndView object.
                break;
            }
            mergedModel.addAllObjects(model.getModel());
            mergedViews.add(model.getViewName());
        } catch (Exception e) {
            throw new Exception(
                    "Controller: " + controller.getClass().getName() + " threw exception: " + e.getMessage(),
                    e);
        }
    }
    mergedModel.addObject("views", mergedViews);
    if (StringUtils.isNotEmpty(this.viewName)) {
        mergedModel.setViewName(this.viewName);
    }
    return mergedModel;
}

From source file:gemlite.core.webapp.settings.ClusterConfigController.java

@RequestMapping(value = "/cluster-config", method = RequestMethod.GET)
    public ModelAndView add(ModelAndView modelAndView) {
        modelAndView = new ModelAndView(PAGE_PREFIX + "cluster-config");

        ConfigService service = JpaContext.getService(ConfigService.class);
        Map<String, String> map = service.getConfig(ConfigTypes.clusterconfig.getValue());
        map.put(ConfigKeys.cluster_rootpsw.getValue(),
                DESUtil.decrypt(map.get(ConfigKeys.cluster_rootpsw.getValue())));
        map.put(ConfigKeys.cluster_userpsw.getValue(),
                DESUtil.decrypt(map.get(ConfigKeys.cluster_userpsw.getValue())));
        if (map != null) {
            modelAndView.addAllObjects(map);
        }/*ww  w  .  ja va2  s  . c  o  m*/
        return modelAndView;
    }

From source file:org.inbio.modeling.web.controller.SpeciesDistributionController.java

@Override
protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response,
        BindException errors) {/* w ww .j  ava2s.c  o m*/

    ModelAndView model = null;
    HttpSession session = null;
    ChooseLimitLayerForm lform = null;
    CurrentInstanceData currentInstanceData = null;

    // retrieve the session Information.
    session = request.getSession();

    //creates the form to the page and upload it.
    lform = new ChooseLimitLayerForm();
    lform.setLayers(FormDTOConverter.convert(layerManager.getSpeciesDistributionLayerList(), Layer.class));

    // Send the layer list to the JSP
    model = new ModelAndView();
    if (errors != null && errors.hasErrors())
        model.addAllObjects(errors.getModel());

    model.setViewName("speciesMap");
    model.addObject("chooseSpeciesMapForm", lform);

    return model;
}

From source file:gemlite.core.webapp.tools.BatchController.java

@RequestMapping(value = "/edit", method = RequestMethod.GET)
    public ModelAndView edit(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView(PAGE_PREFIX + "edit");
        Long id = NumberUtils.toLong(request.getParameter("id"));
        //pnMno//  ww  w  . j  ava  2 s  .c om
        BatchService service = JpaContext.getService(BatchService.class);
        GmBatch batch = service.findOne(id);

        if (batch != null) {
            //batchW
            String cmd = batch.getCmd();
            Map<String, String> map = splitCmd(cmd);
            modelAndView.addAllObjects(map);
        }
        return modelAndView;
    }

From source file:org.inbio.modeling.web.controller.LimitController.java

/**
 * If hit the /columns.html address directly you will be redirected to index
 * @param request/*from w w  w . j  a  va  2s . co  m*/
 * @param response
 * @param errors
 * @return
 * @throws Exception
 */
@Override
protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response,
        BindException errors) {

    CurrentInstanceData currentInstanceData = null;
    ChooseLimitLayerForm lForm = null;
    HttpSession session = null;
    ModelAndView model = null;

    // retrieve the session Information.
    session = request.getSession();

    currentInstanceData = SessionUtils.isSessionAlive(session);

    // asing the columns to the jsp.
    lForm = new ChooseLimitLayerForm();
    lForm.setLayers(currentInstanceData.getLayerList());

    // Send the layer list to the JSP
    model = new ModelAndView();
    model.setViewName("limit");
    model.addObject("limitForm", lForm);
    if (errors != null && errors.hasErrors()) {
        model.addAllObjects(errors.getModel());
    }
    return model;
}

From source file:com.azprogrammer.qgf.controllers.HomeController.java

public ModelAndView doJSON(Map<String, Object> model) {
    ModelAndView mav = new ModelAndView(new JSONView());

    mav.addAllObjects(model);
    return mav;//from www .ja  v  a2  s  .c o  m
}