0

I have a Spring MVC controller set up like so:

@RequestMapping("activityChart")
public ModelAndView activityChart(
  @RequestParam(required=false, value="parent") String parent,
  @RequestParam(required=false, value="expand") String[] expand,
  @ModelAttribute PaginationArgs paginationargs) throws IOException {

// ... return template renderer

}

Where PaginationArgs is a two-field POJO. I want to construct a URL string that includes values for paginationargs. It's easy to do for parent and expand - activityChart?parent=foo&expand=bar&expand=baz, but what's the right way to encode a POJO's fields?

JSP takes care of this in Spring with a <form:form modelAttribute='paginationargs'> tag, but our project isn't using JSP but Jamon instead.

HenryR
  • 8,219
  • 7
  • 35
  • 39

1 Answers1

1

In the simple case parameter names should be the same as the corresponding field names of the model object. So, if PaginationArgs has fields page and size, it would be like page=1&size=10.

In more complex cases Spring can accept parameters whose names are formed as described in 5.4 Bean manipulation and the BeanWrapper.

axtavt
  • 239,438
  • 41
  • 511
  • 482
  • Thanks! Having read through the link, what's still not clear to me is what happens if you have two fields in separate @ModelAttribute POJOs with the same name: how would I say paginationargs1.size and paginationargs2.size explicitly? I've used value="paginationargs1" to set the attribute name, but then writing ?paginationsargs1.size=10 in the URL doesn't seem to work. – HenryR Apr 20 '11 at 20:27