Best approach to pass parameters between pages | Community
Skip to main content
gkambara
Level 2
March 17, 2016
Solved

Best approach to pass parameters between pages

  • March 17, 2016
  • 6 replies
  • 7235 views

Hello,

Frequently, we have to pass parameters between pages. As I started working with AEM (6.1 Sites) recently, I have some questions regarding the best approach to follow:

  • Using query parameters: I think this is the easiest way to pass parameters. However, the page will not be cached and it could be a problem if the page is "heavy".
  • Using cookies: The cost of implementation is low, but if the user disables his cookies, the parameters will be lost.
  • Using Sling Selectors: The page will be cached but in cases that we need to pass multiple parameters, it may become a little confusing.

I could list those approaches and could not decide which one I am going to follow.

Here are some examples of our scenarios:

  1. A input text and a button in page A. When clicking the button, the user is redirected to page B with a parameter containing the value of input text.
  2. A page that has 3 components that could have a custom behavior according to parameters received. Component A is affected by parameter A, Component B is affected by parameter B and Component C is affected by parameter C. None of those parameters are mandatory (component has a default behavior).
  3. Component that list pages using pagination (therefore, affected by pagination parameters).

Are there other approaches? Is there a best approach among all?

Thank you!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

Hi,

that really depends. If you need to handle these different parameters on the server, use request parameters ("?key=value"). Because caching on the dispatcher is not wanted in this case.

If you can handle the parameters on a client side (that means that the server doesn't have to be involved into processing them), you should be able to work a page, which has been taken from the dispatcher cache. So in that case you can add these parameters as a URL fragment ("#mykey=value"), so it is ignored from the server, but can be handled properly on the client side (using Javascript).

kind regards,
Jörg

6 replies

Level 4
March 17, 2016

Make use of the JCR - a strength of AEM is its JCR. Component A updates NodeA and the page that uses the value reads NodeA.

http://stackoverflow.com/questions/21325733/pass-data-from-one-component-to-another-in-adobe-cq

Mani_kumar_
Community Advisor
Community Advisor
March 18, 2016
Hi I think you can use hidden parameters in the page to pass the parameters
kautuk_sahni
Community Manager
Community Manager
March 18, 2016

Hi

Few reference links that might help you:

Link:- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.632.html/forum__o4ij-hi_i_have_create.html

//Passing parameters between CQ pages

        It depends...

        If you just need to pass a selection, like "show med the cities in the country I selected" - use request parameter or Sling Suffix. This is always the default choice imho.

        If it is some sort of wizard, like a registration, then use the session or a cookie. That is if you need to be able to resume the flow or go back and forth. Otherwise, use request parameters.

Link:- http://stackoverflow.com/questions/21325733/pass-data-from-one-component-to-another-in-adobe-cq (it is for components, but could be used across pages as well).

I hope this would help you.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
psjaison
Level 2
March 18, 2016

Other options you can try - Sling Models and JSTL 

Thanks,

Jaison

Jitendra_S_Toma
Level 10
March 18, 2016

Hi, 

To be frank, it depends on how many parameters you want to pass. For instance, if you have one parameter, use as selectors. if there are more than 2 or 3, use query string. 

You already have enough options However, just to add one more option in your list is use request headers to pass parameters.

---Jitendra

gkambara wrote...

Hello,

Frequently, we have to pass parameters between pages. As I started working with AEM (6.1 Sites) recently, I have some questions regarding the best approach to follow:

  • Using query parameters: I think this is the easiest way to pass parameters. However, the page will not be cached and it could be a problem if the page is "heavy".
  • Using cookies: The cost of implementation is low, but if the user disables his cookies, the parameters will be lost.
  • Using Sling Selectors: The page will be cached but in cases that we need to pass multiple parameters, it may become a little confusing.

I could list those approaches and could not decide which one I am going to follow.

Here are some examples of our scenarios:

  1. A input text and a button in page A. When clicking the button, the user is redirected to page B with a parameter containing the value of input text.
  2. A page that has 3 components that could have a custom behavior according to parameters received. Component A is affected by parameter A, Component B is affected by parameter B and Component C is affected by parameter C. None of those parameters are mandatory (component has a default behavior).
  3. Component that list pages using pagination (therefore, affected by pagination parameters).

Are there other approaches? Is there a best approach among all?

Thank you!

 

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
March 19, 2016

Hi,

that really depends. If you need to handle these different parameters on the server, use request parameters ("?key=value"). Because caching on the dispatcher is not wanted in this case.

If you can handle the parameters on a client side (that means that the server doesn't have to be involved into processing them), you should be able to work a page, which has been taken from the dispatcher cache. So in that case you can add these parameters as a URL fragment ("#mykey=value"), so it is ignored from the server, but can be handled properly on the client side (using Javascript).

kind regards,
Jörg