Interesting problem editing a "dynamic" object model
So I have the following object model:
ObjectA has an instance of ObjectB
There are multiple implementations of ObjectB, all with different properties.
How do you handle the binding when the implementation of ObjectB needs to be determined at run time?
I ended up having a Form which contains accessors for all possible values of all the implementations of ObjectB and an apply() method. Form is constructed with an instance of Object A and initialises itself based on the current implementation of ObjectB. Page is rendered, when introspected all values are introspected onto FormA, or FormA.getObjectA, and after introspection FormA.apply, and ObjectA = FormA.getObjectA is called.
All validators etc. work directly on ObjectA, not FormA, but the validators know how to validate the different implementations of ObjectB.
Not particularly nice or elegant, but how else can we do it?
I could implement my own Binder, but that doesn't help the problem of rendering the page, with all possible alternate properties. You cannot bind to attributes that don't exist, and I don't want chunks of jsp that are conditional on the implementation of ObjectB.
An example of what I am wittering on about is say you have a person who has a mode of transport. One implementation of transport is train, with platform, station, time etc. Another implementation is Car with make, model, year etc.
The page that edits Person allows you to specify the mode of transport.