All,
We're building an application which in some respects needs to behave like a
desktop client, where actions in one part of the UI affect components in
another portion of the UI. Our specific case was that we had a left-nav
which contained some links, and a content area which contains an
AjaxTabbedPanel. The links in the left-nav need to be rendered
visible/invisible based on the type of content in the currently selected
tab.
Since we didn't want to have a hard reference from the tab panel to the left
nav panel (because we wanted them to be relatively reusable components), we
decided to create a custom model that is shared between the two. We then
used the attached class/interfaces to:
1) Enable the tab panel to notify the tab model that it has changed it via
Ajax
2) Enable the model in turn to notify the left-nav panel that its model has
changed
3) Allow the left-nav panel to re-render itself by adding it to the
AjaxRequestTarget
So, in our implementation we have a TabModel, which extends AjaxAwareModel.
The LefNavPanel implements AjaxModelAware, and has an indirect reference to
the TabModel. When the currently selected tab is changed via Ajax in the
AjaxTabbedPanel, we call getTabModel().notifyModelChanged(this, target).
The AjaxAwareModel code then looks for any component in the page which
extends AjaxModelAware, and notifies them that the tab model changed.
I'm posting this code because 1) I hope it will prove useful to someone
else, and 2) I'd appreciate any feedback, as I'd rather learn about major
design issues I overlooked sooner rather than later! I see two improvements
we could make. First, add generics to AjaxModelAware, so we can reduce the
number of components who are notified about the model changing by only
looking for components implementing the typed AjaxModelAware interface.
Second, move the code in AjaxAwareModel into some sort of helper class so
that models can participate in this mechanism without having to extend that
class.
BTW, thanks to Frank Bille who actually started me down the path which led
to this.
http://www.nabble.com/file/p13165777/AjaxAwareModel.java AjaxAwareModel.java
http://www.nabble.com/file/p13165777/AjaxModelAware.java AjaxModelAware.java
http://www.nabble.com/file/p13165777/AjaxUpdateAware.java
AjaxUpdateAware.java
Thanks in advance for any thoughts!
Matt Clark
--
View this message in context:
http://www.nabble.com/Updating-distant-%28unrelated%29-components-via-Ajax-when-a-shared-model-changes-tf4610276.html#a13165777
Sent from the Wicket - User mailing list archive at Nabble.com.
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]