Spring MVC – How to access the command object in referenceData method

One thing that I really like about Spring MVC is that if you need a particular method, and you make a reasonable guess where to look for it, you will find it. That is, in fact, a lot like core Java APIs.

I needed a reference to the current form backing object to set up the reference data for the form being displayed. Now, most of Spring tutorials, books etc. only mention the referenceData(request) method that takes a single HttpServletRequest object as parameter, and that was the only one I knew about. So, I was planning to look up the details of the Spring MVC form workflow, but did the usual googling for anyone else running into this method.

And what do I find? A method that does exactly what I needed :)

If your referenceData method depends on the command object, this is what you use –

referenceData(PortletRequest request,
Object command, Errors errors)