Announcement Announcement Module
Collapse
No announcement yet.
Property editors & collection - register to collection or type? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Property editors & collection - register to collection or type?

    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.

    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);
        }
    This was confirmed to work when the command object had a single Proof child object.

    Code:
    private Proof proof;
    Binding on "proof" invoked getAsText to display BindStatus in a form and setAsText when submitting it. So far so good.

    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.

    Code:
    private List<Proof> proofs;
    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!

    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!
Working...
X