I associate the list with several selections in spring, the element does not get its data from the DAO, the data is added from another list of selection options. The user clicks the button and the data is sent to the selection list of several options using jquery.
When the form is placed, data binding is not performed for the element, because its complex data type, so I registered CustomEditor and bound it to @initbinder.
EDITED I updated the code that CollectionEditor now returns the list of citizens back to the view, but I can not get the data in the list to fill in the selected option. I am trying to add items to the list, but jsp still selects null when returning from the server.
Under the code:
CustomCollectionEditor
@InitBinder("crime") protected void initBinder(WebDataBinder binder, HttpServletRequest request, ServletRequestDataBinder victimbinder){ victimbinder.registerCustomEditor(List.class, "victims", new CustomCollectionEditor(List.class){ protected Object convertElement(Object element){ Citizens victims = new Citizens(); String ssNumber = ""; if (element instanceof String){ ssNumber = (String) element; } logger.debug("element is ;" +element); try { int socialSecurityNumber = Integer.parseInt(ssNumber); victims = citizenManager.getCitizen(socialSecurityNumber); } catch (NumberFormatException e) { logger.error(e.getMessage()); } catch (Exception e) { logger.error(e.getMessage()); } return victims; } });
Jsp that populates from DAO in the controller
It contains the filled form DAO class, when the button is pressed, it takes data from the list, adds it to another list, under which it is attached to the POJO
<label>Victims List</label><buttonid="addVictimBtn">/button> <form:select path="" id="dbvictims" title="Victims Of Crime" class="victimLst"> <form:options items="${dbvictims.dbvictimList}" itemValue="socialSecurityNumber" itemLabel="name"/> </form:select>
Jsp select POJO bound item
<label>Victims In Crime</label><button id="removeVictimBtn">-</button> <form:select path="victims" id="victims" title="Victims Of Crime" multiple="multiple" class="victimLst"> <form:options items="${victimList}" itemValue="socialSecurityNumber" itemLabel="name"/> </form:select><form:errors path="victims" class="errors" />