Pregunta

I am trying to create an editor where the user can either select an existing item or create a new one inline. For example, imagine the typical person-address relationship. I want a form where the user, when editing a person, can either select an address from a set of existing addresses or create a new address without moving to a separate form.

Naively, this seems to require two different editors for the same property. Say I have a Person which has Address getAddress() and setAddress(Address). My PersonEditor class would need to have two sub-editors named address of differing types; one to select an existing person and the another a composite of editors to descend into the Address type and allow editing of its properties.

From reading the documentation on CompositeEditor, it seems like I have to make use of it to dynamically select the sub-editor. However, the documentation isn't detailed enough for me to really understand how I should implement the interface. I've tried looking at how ListEditor and OptionalFieldEditor are implemented for clues, but to avail. ListEditor doesn't seem like a straight fit as my sub-editors edit different paths.

For instance, trying to use CompositeEditor, I'm unclear on what createEditorForTraversal and getPathElement should return in my case.

How do I dynamically attach one of two different types of editors to one property?

¿Fue útil?

Solución

I managed to do this in the end. I simply added two editors with the same @Path annotation. I was not expecting the editor framework to allow this, but it seems to work!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top