The Observer Pattern has been one of the most widely used design pattern in Software Development. If not most, many use the pattern for their development to call different independent modules to do processes after the initial action from another module. Certain scenarios like, a display table was updated after an insert call, a window resize after a clicked of a button.
JEE6 introduced a more easy way of using the observer pattern.
Assuming that you have a ManagedBean, with a register transaction method.
- Event<?> will be the one responsible for storing entity or object to be observed.
- A fire method is called passing the entity. (memberEventSrc.fire(newMember));
Once the fire event method is called, it will search for all ManagedBean observing this entity.
- @Observe annotation is used for the final Member class in the method, this is our flag for the method call
- This is located on the ManagedBean – We need a POJO that is class loaded for this process.
The MessageProducerList class is also a ManagedBean that is called after a transaction is made. The fire event from the MemberRegistration ManagedBean will call the method (on the screenshot) to load all the members. These list of members is then loaded to the JSF Page.
Download Source Code
Note: You need Eclipse EE with JBoss Tools installed.