I have a form that uses form:form tags. In particular I bind a multi-select box to a java.util.Set property. It works fine to save a new record, but when I attempt to render an existing element, I get an error message about converting. I'm using @InitBinder and a custom property editor, as listed in the below @Controller code:
Here is the relevant JSP fragment:Code:@Controller @RequestMapping("/admin") public class LiftTypeFormController { Log log = LogFactory.getLog(getClass()); private LiftWorkoutDao liftWorkoutDao; private MuscleGroupEditor muscleGroupEditor; @RequestMapping(value = "/liftType/{liftTypeId}", method = RequestMethod.GET) public String editLiftType(@PathVariable Integer liftTypeId, Model model) { model.addAttribute(liftWorkoutDao.findLiftTypeById(liftTypeId)); return "liftType"; } @InitBinder("liftType") protected void initBinder(WebDataBinder binder) { binder.registerCustomEditor(Integer.class, null, new CustomNumberEditor(Integer.class, new DecimalFormat(), true)); binder.registerCustomEditor(MuscleGroup.class, muscleGroupEditor);
If I take it down to just <form:select path="muscleGroups"/> and nothing else, I still get the following error (but only on edit, not on add new):Code:<td> <form:select path="muscleGroups" size="15" multiple="true" items="${childlessMuscleGroups}" itemValue="muscleGroupId" itemLabel="name"/> <font color="red"><form:errors path="muscleGroups"/></font> </td>
I can also replace the <form:select> tag with old school <spring:bind> and I get the same error. Again, I know the PropertyEditor works since the form works for adding new items, but for some reason it doesn't work on rendering an existing form. I added debugging and can see that the @InitBinder method is invoked prior to rendering the page too. For what it's worth, I've also added a CustomCollection editor and had the exact same result.Code:org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from 'com.espey.common.dto.workout.lift.MuscleGroup' to 'java.lang.String' org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:181) org.springframework.core.convert.support.CollectionToStringConverter.convert(CollectionToStringConverter.java:65) org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:36) org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:184) org.springframework.validation.AbstractPropertyBindingResult.formatFieldValue(AbstractPropertyBindingResult.java:124) org.springframework.validation.AbstractBindingResult.getFieldValue(AbstractBindingResult.java:227) org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:120) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
If I should be using a different approach like formatting or conversion to do this, can someone please point me in the right direction?


Reply With Quote