Moin,
i have also a Observer Pattern build into my application. What i have done is
use a tip from Myfaces.
Set a initialize property to all beans's:
<managed-bean>
<managed-bean-name>ProjectManagerBean</managed-bean-name>
<managed-bean-class>de.webtopproject.ui.bean.project.ProjectManagerBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>serviceLocator</property-name>
<value>#{serviceLocatorBean}</value>
</managed-property>
<managed-property>
<property-name>initialized</property-name>
<value>true</value>
</managed-property>
</managed-bean>
Build two Interfaces Oberserver and Subject and implement this.
Observer has a update method and subjects addOberserver, removeObserver and
notifyObserver.
Now i can do this in my oberservers:
public void setInitialized (boolean state) {
this.projectManagerBean.addObserver(this);
}
The projectManagerBean. is a bean property and is injected with
faces-config.xml to the observers
The notify method of the subject
public void notifyObserver () {
for (Observer o : this.observers) {
o.update();
}
}
The rest is easy. I can call the notifyOberserver and all my observers are
notified.
Am Donnerstag, 15. Februar 2007 16:13 schrieb Beelen, Marco:
> Hello,
>
> In my application I have some managed-bean, which implements some
> Observer-like pattern to notify other beans of some action, so that
> those beans can refresh their state.
>
> In order to do so I added a List<RefreshableBean> to my bean on which
> the action is invoked, which will call the refresh() method on all the
> objects in the list.
>
> In my faces-config.xml I added a managed-property on the bean with a
> list of entries of managed-bean to notify like this:
>
> <managed-bean>
> <managed-bean-name>messageAddBean</managed-bean-name>
> <managed-bean-class>tld.domain.application.MessageAddBean
> </managed-bean-class>
> <managed-bean-scope>session</managed-bean-scope>
> <managed-property>
> <property-name>refreshableBeans</property-name>
> <list-entries>
> <value>#{messageSearchBean}</value>
> <value>#{pendingOpenMessageList}</value>
> <value>#{pendingUrgentMessageList}</value>
> </list-entries>
> </managed-property>
> </managed-bean>
>
> What happens when I invoke the bean, which should call all
> refreshableBeans is that it will iterate over all elements in the list,
> but the list will only contain the first entry from the list ( the
> messageSearchBean ). If I change the order of the values in the xml,
> then the entry which is then the first one will be set in my list.
>
> All referenced managed-bean have <scope>session</scope>, so they should
> be available.
>
> Am I doing something wrong or does myfaces ignore the other entries in
> the list?
> I'm currently using MyFaces-1.1.5-snapshop, but noticed this already
> when I still was using 1.1.3.
>
> I'm also using jsf-spring, so that might be the cause of the problem,
> but thought I ask here first.
>
> Anybody seen this kind of behaviour?
>
> Any help is greatly appreciated!
>
> With kind regards,
> Marco Beelen
>
>
> ---------------------------------------------------------------------------
>--- Notice: This e-mail message, together with any attachments, contains
> information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New
> Jersey, USA 08889), and/or its affiliates (which may be known
> outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD
> and in Japan, as Banyu - direct contact information for affiliates is
> available at http://www.merck.com/contact/contacts.html) that may be
> confidential, proprietary copyrighted and/or legally privileged. It is
> intended solely for the use of the individual or entity named on this
> message. If you are not the intended recipient, and have received this
> message in error, please notify us immediately by reply e-mail and then
> delete it from your system.
>
> ---------------------------------------------------------------------------
>---