Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

Java logic is depend on Adobe Launch script execution

Avatar

Level 8

Hello all,

 

In my AEM application, in the page properties, I have added Adobe Launch script. Called this script in the page template level(in head.html section). So, during page load time, Adobe Launch script will execute and does many things. One part is it adds some details to cookies, say "launch_cookie".

My Java logic(which I am calling from few components.) will read the launch_cookie value from cookie and uses the values. Now, during page load time Java logic executes first. Then Adobe launch script is adding the value to cookies. So, during the first page load, my java logic is not getting the proper values from cookie. How can i resolve this issue?

Adobe Launch script should execute first. Then, java logic should execute.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi 

 

The requirment you want to achieve is not possible because Launch Script is JS which is client side script which means it needs user browser/agent to get executed. Java code where you have written some logic on these cookies is server side script and as you mentioned when page is loaded, server side script is executed first and vice versa is not possible.

 

If you really want to achieve some task which is dependent on these cookies, you must take your logic from java(server side) to JS(client side) keeping following in mind:

  1. There are js libraries that allow to read cookies client side which you can use and apply logic and change view in your component.
  2. If logic requires server side java execution, then consider creating some servlet which you can call from js after page load. Since, cookies will be created till that time, servlet will get these cookies in request object.

Hope it helps!

Thanks,

Nupur

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi 

 

The requirment you want to achieve is not possible because Launch Script is JS which is client side script which means it needs user browser/agent to get executed. Java code where you have written some logic on these cookies is server side script and as you mentioned when page is loaded, server side script is executed first and vice versa is not possible.

 

If you really want to achieve some task which is dependent on these cookies, you must take your logic from java(server side) to JS(client side) keeping following in mind:

  1. There are js libraries that allow to read cookies client side which you can use and apply logic and change view in your component.
  2. If logic requires server side java execution, then consider creating some servlet which you can call from js after page load. Since, cookies will be created till that time, servlet will get these cookies in request object.

Hope it helps!

Thanks,

Nupur