I have a page that has a list of custom items i register a custom editor in the init binder of the controller to allow data binding. The list is passed form the view. The problem i am having is i am on a view that is bind to a different object.However the both objects have an attribute in common crimeRecNo.
I have created a binder function under when the data is passed from the view to the controller for the custom object list however i would like to create a binder that receives an Integer and returns a list. Under is an example of what i have thus far, however it isnt binding:
I need to know how to register a custom editor that accepts a Integer crimeRecNo and returns a list and bind it to the list.
Binder Function
This is just not binding
crimeRecNoBinderVictimList.registerCustomEditor(Integer.class, "crimeRecNo", new CustomCollectionEditor(List.class){
protected Object convertElement(Object element) {
List<Citizens> victimList = new ArrayList<Citizens>();
String crimeRecNo = null
if (element instanceof String) {
crimeRecNo = (String) element;
}
logger.info("Inside CrimeRecNo Binder crimeRecNoBinderVictimList " + crimeRecNo);
try {
victimList = citizenManager.getListOfVictimsByCrimeRecNo(Integer.parseInt(crimeRecNo));
} catch (Exception e) {
logger.error("Error In crimeRecNoBinderVictimList "+e.getMessage());
}
return victimList;
}
});
Error
102348 [http-bio-8084-exec-10] DEBUG org.springframework.beans.TypeConverterDelegate - Converting String to [int] using property editor [com.crimetrack.web.CrimeController$2@4b9e3acd]
102348 [http-bio-8084-exec-10] INFO com.crimetrack.web.CrimeController - Inside CrimeRecNo Binder crimeRecNoBinderCriminalList null
102348 [http-bio-8084-exec-10] ERROR com.crimetrack.web.CrimeController - null
102358 [http-bio-8084-exec-10] INFO com.crimetrack.web.CrimeController - Inside CrimeRecNo Binder crimeRecNoBinderCriminalList 6
Good question,
I'm not sure, but this tutorial on Spring's
@InitBinder
may help:http://howtoprogramwithjava.com/session35