Seam component events
A very powerful feature in Seam that usually doesn’t get enough attention in my opinion is component-driven events. Seam component can raise or throw arbitrary event and any number of other Seam components can observe or listen to these events. This truly creates a loose coupled architecture. Components raise events and anyone who cares listens to the event. The components are not connected to each other in any way.
Let’s start with CourseManager component:
@Name("courseManager") public class CourseManager { private String name; // setter and getter @Out(required=false) private String studentName; @Logger Log log; @RaiseEvent("courseDropped") public void drop() { studentName = name; log.info("course dropped"); } }
In component above when drop() method is invoked, courseDropped event will be raised via @RaiseEvent annotation. Once invocation is done, the component will outject studentName variable.
Although data can passed with the event, a better way is to use bijection in Seam. The name variable would most likely be submitted from a JSF page. Its value is assigned to studentName component variable and studentName is outjected after the method invokation. Anyone who is interested in this event can listen to it and also get the data associated with the event (via injection).
Read more »


