Normally, a frontend such as a web application (e.g. JSF) is used to retrieve data from a system and display it. User interaction is required: a user pulls up a website and e.g. clicks a button which in turn triggers a whole round trip process (view calls controller, controller informs model, model updates and notifies view via controller again).
In my setup I don't have any user interaction because my webapp is a view only. No user can do any CRUD actions (except Read). The "user interaction" comes so to speak from my backend: This system runs the entirety of business logic and receives user interactions through other channels than the webapp. However, all changes within the backend need to be somehow pushed into the webapp frontend.
I am using JavaEE, more precisely EJB 3.2, JSF 2.2 and PrimeFaces 5.1 (as well as JMS 2.x, WildFly 8.2, OmniFaces 2.0)
My backend communicates changes via JMS. I defined a MessageListener within my webapp that listens to all incoming changes. These changes are pushed into the model (EJBs).
As far as my knowledge goes should a model never know anything about it's view: the model is completely agnostic to the view. In JavaEE terms this means that my EJBs (model) should not inject any ManagedBeans (controller).
Now here is my question: How should the model inform the controller/view about changes, so that they get reflected within the view?
- Am I forced to use something like CDI Events?
- Or in case of PrimeFaces, should I use PrimeFaces Push (WebSocket implementation using Atmosphere) that kinda simulates a user interaction? In other words, should my JMS MessageListener directly push the changes to all clients (browsers) via WebSocket and then use AJAX to simulate an user interaction (which in turn does nothing else than what a "normal" user would trigger in the webapp)?
- Or how about the old fashioned way according to Observer Pattern: Every managed bean that needs to be notified I add as listener to the EJB with help of @PostConstruct and also make sure that the listener gets removed with @PreDestroy?