PDA

View Full Version : Passing Data Between Controllers


jazman
Apr 26th, 2007, 12:13 PM
Hi Guys,

I have two controllers and I want to pass some data between the two of them and I'm not quiet sure how I should go about doing this. In my first controller, HistoryController I make a call to my database and store the results in a list. This list I want to display in the view report.jsp and also pass control to my second controller (reportController), like so;


return new ModelAndView(new RedirectView("report.htm"), "orders", orders);


then I retrieve the object in my second controller, ReportController, with the following;


protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception{

ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("message", request.getParameter("message"));

return modelAndView;
}



this is then called in the view with the following;


<core:forEach var="order" items="${orders}" varStatus="status">
<core:out value="${order.orderID}"/>

now the problem is I get an error message saying that the view cannot find the relevant attribute of the object i've sent through. I can send simple String objects and messages, but i cannot seem to send across a list. Does anybody know how else I would be able to achieve this?

fox
Apr 27th, 2007, 11:17 AM
in request you have getAttribute / setAttribute methods which can be used for storing objects