2

I was able to integrate ActiveMQ and create a JMS consumer into my OpenXava application. Now, I need to update certain transient view with the data received in the message, which it have several issues to consider, by example... how to go from a JMS listener java class and push the changes to the current view? ... and supposing the specific view is the current!!!, but the current view could be any one of the several possibles views in the whole application!!! ... so? so?... then I did think, I will persist the JMS messages into some entity (as a temporal storage in DB) even that will incur in a low performance, but then after that... how I will push the recent changes if some user is looking the transient view.

I was used to build my webapps using some JSF implementation with ajax enabled, and then I could receive the message in the JMS listener and then get a jsf managed bean reference and use Ajax push to refresh all the sessions that could be opened by one or several users looking into the app, so this always produced a kind of real time application, which update the any opened view (if the view is the one that the user is watching).

So, is there a way to accomplish that with a JMS listener class into my OX app??

Thanks in advance,

HayrolR
  • 761
  • 5
  • 9

1 Answers1

1

An option can be using JavaScript to calling regularly to know if a new record is added in the table or whatever, and if it is case refreshing.

If you're liferay you can create a portlet in that page with the JavaScript code. This code can do the call using DWR, and if there is new data it can call to the "CRUD.refresh" action directly.

Something like this:

refreshData = function() {
   openxava.executeAction('YourApplication', 'YourModule', '', false, 'CRUD.refresh')
   setTimeout('refreshData()', 5000);
}
setTimeout('refreshData()', 5000);

I didn't test this code, so surely it does not work as is. Take it as an idea.

Really, this is a dirty trick. The ideal would be that OpenXava would have direct support for comet, you could accomplish this just calling to an method in the server. Do you think that adding comet support to OX worth?

javierpaniza
  • 677
  • 4
  • 10
  • Hi Javier, I don't know how to implement that dirty trick into my OX app... I have built Ajax Push apps with other tools, and that produce nice apps that only refresh the sections or components of the page which needs the update, avoiding periodical and maybe uneeded updates on the whole page and of course the update cames from some server's event. I'm pretty sure that if OX could support Comet it should be wonderful!. – HayrolR Dec 27 '12 at 22:20
  • Hi @HayrolR, try to do the trick and if you have troubles I'll help you. Start with a JavaScript code that call "CRUD.refresh" regularly. This is not the optimal but it's easy to implement. Afterwards, add the call to DWR to ask for changes and only call "CRUD.refresh" when needed. – javierpaniza Jan 02 '13 at 12:50
  • Hi @HayrolR, about adding Comet support to OpenXava, we need a volunteer. Are you willing to add this feature to OX and contribute it? – javierpaniza Jan 02 '13 at 12:51
  • Ok Javier I will try it, but where should I add the JavaScript code?, can you show me an example?. Btw, could be nice to contribute about Comet, even I'm just getting into OX now and I don't know too much about the way it's developed. So, is there some documentation about?, maybe I can speed up my learning. – HayrolR Jan 02 '13 at 19:59
  • You can put the JavaScript code in a custom portlet and place that portlet in the same page of the OX modules. If you want to execute your app with no portal you can put you JavaScript code in a JS file inside the folder web/xava/editors/js – javierpaniza Jan 07 '13 at 14:24
  • There is not documentation about the inner OpenXava architecture, though the doc for the application developer is ver exhaustive. You have to learn about OpenXava guts seeing and modifying the code. My advice is that imagine the best way to use Comet from the application developer perspective. That is, don't think in how to implment it, but in if I have to implement it for you what do ask me to implement. Then I'll give you some tips about how to implement it. Given that it is not a help issue, we can manage it in the OX developers forum (even in Spanish if you prefer). – javierpaniza Jan 07 '13 at 14:27
  • Hi Javier, I'm going to start designing an use case on how this feature could be useful at the user level. I can think in some new annotation(s), action(s) and other stuffs that need to be developed to provide that feature (Comet support). – HayrolR Feb 07 '13 at 04:59
  • But, in the meantime, as I am using Liferay for now, **can you give me an example of some JavaScript code that I can put in one of the Liferay page spot for that?, I need to know how to access the objects coming into the Views and also how to access the OX middle and/or the persistent layer in the best way**. I can do that at DB layer in a raw way, but I'm sure that it's not the best way. – HayrolR Feb 07 '13 at 04:59
  • About your idea of designing the comet feature for OX is just wondeful. Thanks. About the code, I'm going to edit this question to include some code, but I didn't test the code, so surely it would fail, take it as a initial idea – javierpaniza Feb 08 '13 at 13:06
  • Excellent!, no problem if it's not tested yet. I know your code will be 99% accuracy, so let me to put the remaining 1%. – HayrolR Feb 08 '13 at 17:07