views:

40

answers:

2

I'm using Spring MVC 3 for a web app. In the app a URI template is supposed to be handled by a controller method, which then passes an attribute to a view. Currently, the controller does handle the request, and it even forwards to the correct view. However, it does NOT pass the attribute to the view. Below are the URI template, controller method and relevent jsp tags. Anyone see what is wrong?

URI:

/home/{status}

Controller:

@RequestMapping("/home")
@Controller
public class HomeController {
...
...
@RequestMapping(value="/{status}") 
public String homeStatusView(@PathVariable("status") String status, ModelMap model) {
model.addAttribute("status", status);
return "home";
}
}

JSP:

...
<c:if test="${not empty status}">
<span class="status">Your status is available...</span>
</c:if>
...
A: 

This is a slightly different approach but should work:

@RequestMapping(value="/{status}") 
public ModelAndView homeStatusView(@PathVariable("status") String status) {

  ModelAndView mav = new ModelAndView("home");
  mav.addAttribute("status", status);
  return mav;

}
Scobal
+1  A: 

I use it in the same way as yours though I use Model class instead of ModelMap, though I think it works as well with ModelMap. On the other hand when you write:

<span class="status">Your status is available...</span>

did you mean something like this?:

<span class="${status}">Your status is available...</span>

if you don't use ${} it won't be printed.

Javi