This is using Spring MVC 2.5. My code is simplified for brevity.
I wrote a custom editor for a type we'll call Proof, and registered it in my form controller.
This was confirmed to work when the command object had a single Proof child object.Code:private static final ProofEditor PROOF_EDITOR = new ProofEditor(); protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { binder.registerCustomEditor(Proof.class, PROOF_EDITOR); super.initBinder(request, binder); }
Binding on "proof" invoked getAsText to display BindStatus in a form and setAsText when submitting it. So far so good.Code:private Proof proof;
Now I've changed the single Proof to a List<Proof> with the bind path "proofs". The bound form controls are checkboxes, so the values are all submitted with the same path, with no ordering.
What I've found is that, on submit, the data binder still recognizes my ProofEdtior as the custom editor for a List<Proof>, and converts the strings to a Proof collection. Great!Code:private List<Proof> proofs;
But displaying the form, a BindStatus on "proofs" does not go through the ProofEditor's getAsText. The BindStatus value just returns the List. I stepped through remote debugging, and when PropertyEditorRegistrySupport looks for a custom editor on "proofs" it never checks for any type but List.
So here is my question -- despite the fact that a custom editor registered for Proof worked on setting a Collection<Proof>, is it even supposed to work for getting BindStatus on one? Or am I supposed to register an editor for the Collection instead?
The PropertyEditorRegistry javadoc makes it sound like a custom editor works on both a type and collections of that type, but is not perfectly clear to me. Thanks!


Reply With Quote
