Tuesday, 5 June 2012

Spring; Tags for drop-downs

For some reason upgrading from spring 2 -> 3.1.0 has caused me a good deal of grief with drop-downs.

My old code used to specify a method called referenceData() in the Controller, which would basically put a set of lists into map object, and the framework would make available in the session object.  This meant that the following bit of code in a JSP worked:


 
<td align="center">Registration Status:</td>

<td> <form:select path="registrationstatus" items="${registrationStatusList}"/> </td>


Thus any options, stored in a db table,  in this case registration statii could be taken out of the db by the Controller, ready for use in the JSP.

However after switching to spring 3, this seems to work only intermittently, leading me to suspect that there is a different way of handling objects on the session, or perhaps some kind of caching mechanism which has bugs or that the session no longer automatically runs the referenceData() method, hence I have had to get the items into the session object separately.  After losing the best part of a morning trying to track this down I am still at a loss to know why the referenceData() method now works intermittantly, however life is short so now each of my Controller classes has a new method:


 
 protected void setupFormData(HttpServletRequest request){

        List<String> registrationStatusList = getAllRegistrationStatus();

        request.setAttribute("registrationStatusList", registrationStatusList);

        List<Person> personList = getAllPeople();

        request.setAttribute("personList", personList);

    }


This seems to allow the JSP code above to work quite happily.


No comments:

Post a Comment