Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to make a page property Hight priority than others

Avatar

Level 2

Hello everyone! I've encountered a minor issue. I've recently introduced a new property called "cookie settings" to all page properties. The intention behind this addition is to empower authors to independently create cookies at the page level, eliminating the need for hardcoding in our codebase. So far, everything is functioning smoothly.

However, a challenge arises when authors configure cookies at the page level using the page properties and subsequently add a redirect from the advanced tab, also at the page level. The redirect tends to occur before the cookies are created at the page level, leading to undesired behavior.

I'm reaching out to seek advice or insights from anyone who has faced a similar scenario. What would be the best approach to ensure that cookies are created first at the page level before allowing the redirect to take effect? Thank you in advance for your assistance!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Ayoub_Tabai 
You can't set a cookie from sling model if page execution is stop due to redirect.

you need to write a custom filter to read value from jcr node and set a cookie before redirect happens.



Arun Patidar

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @Ayoub_Tabai 
Since the redirect is performed server side before serving actual page HTML from AEM. So there is no ways you can achieve this at client side.

 

What you can do is create a sling filter that that will set a cookie from severs side.

 

This custom filter must be trigger before the OOTB redirect filter.



Arun Patidar

Avatar

Level 2

Hello! I'm not handling this from the client side. Instead, I have a model and an implementation. I utilize a cqdialog that contains a multifield where users can input the cookie name and its value. Subsequently, I read this multifield in my Sling model, managing it from the server side.

Avatar

Correct answer by
Community Advisor

Hi @Ayoub_Tabai 
You can't set a cookie from sling model if page execution is stop due to redirect.

you need to write a custom filter to read value from jcr node and set a cookie before redirect happens.



Arun Patidar

Avatar

Community Advisor

You have to override the com.adobe.cq.wcm.core.components.models.Page on your end. Then you can achieve your goal.

@Model(adaptables = SlingHttpServletRequest.class, adapters = Page.class, resourceType = HbkPageImpl.RESOURCE_TYPE)
public class YourPageImpl extends AbstractComponentImpl implements Page {
//Your code goes here
//Also check the core component page impl
}