I created a publisher and an observer of an event. I would like to know if there's a way to return values from an observer to a publisher and even display FacesMessages from Observer in jsf page. Please see my sample code below:
@Stateful
@Scope(ScopeType.SESSION)
@Name(myClass
)
public class MyClass{
public void myMethod() {
Events events = Events.instance();
events.raiseAsynchronousEvent(observerName
);
}
}
@Name(myObserver
)
public class ObserverClass {
@Observer(observerName
)
public String observerMethod() {
FacesMessages.instance().add(I want to show this message on the screen for users
);
return can I return this String to the event producer - myClass.myMethod()
;
}
}
The code itself will tell you what I want to do. Once the event is completed, I want to display some message (as shown in the FacesMesssages in the observerMethod.) But this doesn't work. Also, how can I handle an exception? For now, I think I can use FacesMessages for user-friendly message (if this is possible.) is there any better way for exception handling in this case?
Please help.
Thank you.
Michelle
Since its asynchronous you can't return a value to the publisher. You could have the publisher register as an observer for the exception event and have the observer publish that exception.