Announcement Announcement Module
Collapse
No announcement yet.
render ModelAndView programmatically Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • render ModelAndView programmatically

    I am wondering is it possible to generate ModelAndView's output programatically and not via controller's return parameter. For example: I have the following method that returns a compiled html:

    Code:
    @RequestMapping(value = "/get-list", method = RequestMethod.GET, headers = BaseController.AJAX_HEADER)
    public ModelAndView getList(@RequestParam(value = "page", required = true) Integer page,
                @ActiveUser User activeUser) {
            ModelAndView result = null;
    
            try {
                result = new ModelAndView("administration/events-log/list");
                result.addObject("events", eventsLogService.getList(page, Config.RECORDS_PER_PAGE));
            }
            catch (Exception e) {
                log(e, activeUser.getUsername());
            }
    
            return result;
        }
    What I want is to create something like that:

    Code:
    @RequestMapping(value = "/get-list", method = RequestMethod.GET, headers = BaseController.AJAX_HEADER)
    public @ResponseBody HashMap<String, Object> getList(@RequestParam(value = "page", required = true) Integer page,
                @ActiveUser User activeUser) {
            HashMap<String, Object> json = new HashMap<String, Object>();
    
            try {
                json.put("error", 0);
                ModelAndView result = new ModelAndView("administration/events-log/list");
                result.addObject("events", eventsLogService.getList(page, Config.RECORDS_PER_PAGE));
    
                json.put("content", result);
    
            }
            catch (Exception e) {
                /**/
            }
    
            return json;
        }
    so the JSON object that will be sended back to the client will look: {'error': 0, 'content': compiled_html}

    Any thoughts? Thank you
Working...
X