1

I have a requirement where on ajax call i need to populate the table. I am using jquery ajax and spring mvc. Below is the code i am using to populate the bean using modelattribute, but when i go to the jsp modelattribute is not available at all. Any help would be really appreciable.

@RequestMapping(value = "/getFullSchedule", method = RequestMethod.GET, produces="application/json")
public @ResponseBody ScheduleBean displayFullSchedule(@ModelAttribute("scheduleBean") ScheduleBean scheduleBean,
        @RequestParam(value= "callCenterId", required=true, defaultValue = "-1") String callCenterId,
        @RequestParam(value= "queueId", required=true, defaultValue = "-1") String queueId, Model model)
        throws ServiceException {

    logger.debug("Getting full schedule for callCenterId(" + callCenterId + ") and queueId(" + queueId + ")"); 

    QueueScheduleFull fullSchedule = scheduleService.get7DaySchedule(callCenterId, queueId);

    logger.debug(fullSchedule);


//  ScheduleBean scheduleBean = new ScheduleBean();
    scheduleBean.setCallCenterId(fullSchedule.getCallCenterId());
    scheduleBean.setQueueId(fullSchedule.getQueueId());
    scheduleBean.setVdnDesc(fullSchedule.getVdnDesc());

    Collection<DaySchedule> days = new ArrayList<DaySchedule>();
    days.add(fullSchedule.getWeeklySchedule().getMonday());
    days.add(fullSchedule.getWeeklySchedule().getTuesday());
    days.add(fullSchedule.getWeeklySchedule().getWednesday());
    days.add(fullSchedule.getWeeklySchedule().getThursday());
    days.add(fullSchedule.getWeeklySchedule().getFriday());
    days.add(fullSchedule.getWeeklySchedule().getSaturday());
    days.add(fullSchedule.getWeeklySchedule().getSunday());
    scheduleBean.setDays(days);
    model.addAttribute("scheduleBean", scheduleBean);
    model.addAttribute("chetan", "test");
    return scheduleBean;
}

And the jsp part looks like below

<c:out value="HELLO${chetan}"></c:out>

    <c:out value="Help me out here${scheduleBean.days[0].startTime}"/>

    <display:table htmlId="scheduleTable" name="${scheduleBean.days}" pagesize="15" 
        export="false" sort="list" cellpadding="0" cellspacing="0"
        width="100%" requestURI="" id="fullScheduleTable" align="left" class="pure-table pure-table-bordered">

        <display:column title = "abc">
            <div>${fullScheduleTable.startTime}</div>
        </display:column>
    </display:table> 

Nothing in the model or ModelAttribute is available on the jsp page.

I have also added the jackson mapper in the dispatcher-servlet and still no go.

<mvc:annotation-driven />
<bean id="jacksonMessageConverter"
    class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
chetank
  • 392
  • 3
  • 17
  • `@ModelAttribute` is for loading a model attribute from Flash or Session or a `@ModelAttribute`-annotated method. I don't see you having any of those. – Neil McGuigan Mar 17 '15 at 19:30
  • so how do i pass value to display tag when i get success as an ScheduleBean object in JSON format?. Since scheduleBean contains a property as days which will be an array and display tag expect a list pass to its name attribute to display the table. – chetank Mar 17 '15 at 19:44
  • 1
    You really need to simplify and figure out what you're doing. Get your JSP working by itself. Get your JSON working by itself. Then integrate. You don't usually use `@ModelAttribute` or `Model` with `@ResponseBody`. There are plenty of examples online to get each working . – Neil McGuigan Mar 17 '15 at 20:25

0 Answers0