PDA

View Full Version : Passing Object data between controllers


bellyboyke
Jun 10th, 2008, 11:23 AM
I have one simpleform controller and another controller

In one simpleform controller a search action can be done that returns a list of
visitors. When the submit button is pressed i want to show this list of visitors
on another jsp page using jstl.

So i put the visitor list data in the model

protected ModelAndView onSubmit(Object command) throws Exception
{
HashMap map = new HashMap();

map.put("foundVisitors", visitorManager.searchVisitor((Visitor) command));

return new ModelAndView(new RedirectView(getSuccessView()),"model",map);
}

but now in another controller i want to be able to readout this model data

public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {

Map myModel = new HashMap(arg0.getParameterMap());

return new ModelAndView("searchResult", "model", myModel);
}

And i write the following jstl code on my jsp page :

<c:forEach items="${model.foundVisitors}" var="visitors">
<c:out value="${visitors.firstName}" />
<c:out value="${visitors.lastName}" />
<c:out value="${visitors.company}" />
<br>
</c:forEach>

Nothing is displayed :(

So i put some logging in the receiving controller and it seems that no map data is read out, so my question is how do i pass model data thats filled with a list of object from one controller to the other controller ? How do I read it out in the second controller ?

noon
Jun 10th, 2008, 01:51 PM
You could achieve this with one simpleformcontroller but if you want to use two controllers, you could save the object in first controller before the redirect to HTTP session and read it from there in 2nd controller.

Oh... in the future, use CODE tags when you're posting some code excerpts.