4

I am currently reading from ActiveMQ with a Message driven bean (EJB3) in the back end. The problem I am facing is that I have to update a table in my JSF page as soon as I receive the message from ActiveMQ in the message driven bean.

Any suggestions of the technologies I can try would be great. I am currently using primefaces and glassfish.

Thx

MaDa
  • 10,511
  • 9
  • 46
  • 84

2 Answers2

2

You could use primefaces poll to periodically check if there are new messages

<h:form>  
     <p:dataTable id="msgTable" var="msg" value="#{tableBean.messages} ">
     ...
     </p:dataTable>

     <p:poll interval="3"   
             actionListener="#{mdBean.messagesAvailable}" update="msgTable" />  
</h:form> 

See http://97.107.138.40:8080/prime-showcase/ui/ajaxPollHome.jsf for more detail.

Jose Diaz
  • 5,353
  • 1
  • 31
  • 29
  • Thanks for the response. I ended up using primefaces poll and alerting the other clients via the p:push method in order to alert everyone at the same time. This is however not ideal. The ideal should be that the onmessage() method of the MDB should do something to notifiy all clients that page should update, but I don't know of a way to call a managed bean backend method or similar from the message driven bean. I implemented the activeMQ and MDB as an alert mechanism to not poll the database every few seconds from every client. ActiveMQ message to client...client checks database. – Jaco de Villiers Aug 02 '10 at 04:28
0

You cannot really call a (JSF) managed bean method directly from a message driven bean, since the scopes and times during which they are active are completely different.

The managed bean basically is active during an HTTP request. Afterwards its state might still be stored somewhere (i.e. if application, session or conversation scope is used), but it's not actively doing anything.

What you could do is use a technology like Comet, where you basically suspend the request from the backing bean. You can then let the backing bean wait for something before resuming the request again. You can let the managed bean listen to the same JMS queue that the message driven bean is listening to (assuming JMS is used), or you can let the managed bean listen to the CDI event bus. As soon as the MDB receives something from ActiveMQ, the MDB can put this on the CDI event bus and the backing bean will receive it.

In effect the MDB is then functioning as a bridge component.

There were a few presentations on Devoxx '10 that demonstrated something quite similar to what you are asking.

I think among others this presentation went into that stuff: http://www.adam-bien.com/roller/abien/entry/pets_and_aliens_running_on

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140