Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

how to send org.osgi.service.event.Event to frontend javascript

Avatar

Employee

I have a requirement where i need to update the status of an icon based on an 

org.osgi.service.event.Event

 the icon needs to be hidden or visible or title needs to be changed based on the value of that event. How can we send this event to the front end javascript so that i can update the ui according to this?

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

This is not that easy for some reasons:

  1. Native AEM does not support a server-side-push possibility.
  2. Your client needs to register its interest ini a certain OSGI event on the server.
  3. How would play together via cache? You would need to bypass for this type of push.

With these constraints I think that you should design your application in a way, which is capable to avoid this dependency, mostyl for scalability reasons.

 

View solution in original post

9 Replies

Avatar

Community Advisor

Hi @tasunil,

 

Once you get the required value in sightly, you can share it with the front end as per my answer here.

 

Hope this helps.

 

Thanks,

Kiran Vedantam

Avatar

Employee
Hi @Kiran_Vedantam the main issue which i am facing is how to send the osgi event to the JS. From JS to HTML i can do the binding. but how to make the event reach the JS?

Avatar

Community Advisor

Hi @tasunil,

 

How are you triggering the event? If you cannot get the event value in HTML, you can create a node in JCR in a specified location with true or false values, and then once the event is triggered, in JS consume that node value.

 

Thanks,
Kiran Vedantam

Avatar

Employee
Hi @Kiran_Vedantam i am using eventAdmin.sendEvent("customevent"). So if i a send a custom event from this i can document.on("customevent") in javascript??

Avatar

Employee
also ou can create a node in JCR in a specified location with true or false values, and then once the event is triggered, in JS consume that node value. how to constantly monitor this in JS? with on change event in JS ?

Avatar

Community Advisor

Hi,

Do you need to update the icon asynchronously or on page load.

If it is on page load then you can read those node values using nodepath.json and update it.

 

But if there is a monitoring/dashborad page that needs to be updated, in that case, you need to write a polling service in javascript to fetch the same data and update the icon, title.



Arun Patidar

Avatar

Employee
hello @arunpatidar no i need to do it asynchronously. what happens is i send an event to process something then if it is successfull i need to update the icon on the same page

Avatar

Community Advisor
you can return the response from the request you make to process and based on the response you can update. This is the normal flow. otherwise you need to store the results in cookie and read thos evalues


Arun Patidar

Avatar

Correct answer by
Employee Advisor

This is not that easy for some reasons:

  1. Native AEM does not support a server-side-push possibility.
  2. Your client needs to register its interest ini a certain OSGI event on the server.
  3. How would play together via cache? You would need to bypass for this type of push.

With these constraints I think that you should design your application in a way, which is capable to avoid this dependency, mostyl for scalability reasons.