Results 1 to 1 of 1

Thread: Pre-populate dropdown selections Spring MVC 2.5

  1. #1
    Join Date
    Jan 2011
    Posts
    5

    Default Pre-populate dropdown selections Spring MVC 2.5

    Hello All,
    I'm new to Spring and need to populate a select box with dates from a service call to a database before the jsp form loads. I'm using the SimpleFormController and wasn't sure how to do this? I have a controller that is setup and working to get the form submission and call another service, but I want to access a date populater service before the page loads to get these dates pre-populated for the user to select for some additional submission criteria. I read that you can use a formBackingObject for something like this. Is this the best way and does anyone have any basic examples?

    Thanks,
    James

    Well, from what I could gather, I came up with some code that worked. Not sure if this is the right way to do it, but I used:
    <code>
    @Override
    protected Object formBackingObject(HttpServletRequest request)
    throws Exception {
    List<Date> datesList = xxxService.getDates();
    request.setAttribute("datesList", datesList);
    return super.formBackingObject(request);
    }
    <code>
    The form backing object seemed to be the correct way to do this, but is it a best practice to manually set the request object with the results of the service call?

    Well, yes you can use the formBackingObject, but I realize now that is really for form selection data. To pre-populate the form you use the referenceData method and it worked fine.
    Last edited by jamesEston; Jan 27th, 2011 at 12:08 PM. Reason: Found better solution

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •