Hi Joel
Thank you for your considered response.
I understand that I'm not in the majority of use cases so it's
understandable why the widget infrastructure emerged in it's current
design. However it's still nice to know that you've read and
understood my problem and confirmed that my take on the situation is
correct because you might have said something like 'oh just use
functionality x y and z' which I might have been unaware of.
Although I understand how two 'instances' might work in the final
javascript code, I'm not sure that hosted mode was designed to cope
with this scenario as it means there would be two instances
simultaneously with different states, a second entrypoint class etc.
At the moment I think I'm going to take a stab at reworking the DOM of
the iframe. This is really akin to building my own widget
infrastructure. I might try branching the GWT code or respective
classes first and see how far I can get with that while I'm feeling
bold.
I hear what you're saying about a solution requiring every widget to
need a constructor that takes in a Document. Although that would be
the most honest solution as it describes the full nature of the
problem, it does make it ugly for the most common use case where
people would not want to have to manage a seemingly redundant Document
instance.
However there is potentially another way.
Given that widgets have the concept of being attached or detached from
the DOM, if the creation of the widget's elements were delayed until
it was added to it's parent, the passing of the Document could be
hidden from the user.
So...
1) All widgets would implement the interface void create(Document doc)
or something similar.
2) The contents of the constructor for all widgets, currently
responsible for the creation of it's elements, would be moved to it's
create(Document doc) implementation.
3) When the widget was added to it's parent panel, then the create
(...) method would be invoked passing the Document of the parent to
the child. This Document would be responsible for element creation.
Likely the parent would call setDocument() first on the widget, so as
to alleviate widget maintainers from having responsibility to store
the document themselves.
4) If a widget had already been created and had div elements linked to
a specific Document, trying to reparent the widget to a different
panel of a different document would throw a GWT managed error, so
you'd never get the case where the browser would have undefined
behaviour or crash.
Further, in order to roll out such a huge change in operation with no
disturbance to existing GWT apps, I'd create a
Widget.DocumentSpecificDelayedCreation static boolean flag defaulted
to false. Under this default mode the create(...) method would be
called in the constructor as per usual with the default Document and
not when the widget was attached to it's parent. This means that no
changes would have to occur at all for existing apps or 3rd party
widgets. It does mean that 3rd party widgets would have to overload an
implementation of create(...) and write their constructors correctly
if they wanted to support this DocumentSpecificDelayedCreation
behaviour.
Quite elegant, no? ;-)
Thanx again for a great product! And with your previous response,
proved even better service!
Regards
Daniel.