RequestParameterMap is behaving differently in AEM 6.3 | Community
Skip to main content
krish1442
Level 2
Jan 15, 2018 12:43 PM UTC
Solved

RequestParameterMap is behaving differently in AEM 6.3

When we have parameters in the url, we can use request.requestParameterMap[value] ....It was working fine in 6.1 but in 6.3 after CFP1 installation ,its working only when the url has parameter else its throwing an error "org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: null ".. I tried to validate to put the code only when the url has parameters .but I am not able to check whether the url has parameters or not in sightly ...Any thoughts on this? Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
krish1442
krish1442Accepted solution
Level 2
Jan 16, 2018 3:22 PM UTC

Thanks neelesh for the reply..

It will work only when you have one query parameter but in our case we had two query parameters, For some pages one queryparameter will be used and for some pages the other queryparameter will be used in the same html.

For Example : ?q=&tag=

For that purpose I was validating with this line of code :
<sly data-sly-test="${request.queryString}">  or
<sly data-sly-test="${request.requestParameterMap}" data-sly-unwrap> this will also work.

and also I have written some JS for fetching the two queryparameters and assigning it to some variable in JS itself and returning it in html.


In that way it was fixed.

6 replies

krish1442
krish1442AuthorAccepted solution
Level 2
Jan 16, 2018 3:22 PM UTC

Thanks neelesh for the reply..

It will work only when you have one query parameter but in our case we had two query parameters, For some pages one queryparameter will be used and for some pages the other queryparameter will be used in the same html.

For Example : ?q=&tag=

For that purpose I was validating with this line of code :
<sly data-sly-test="${request.queryString}">  or
<sly data-sly-test="${request.requestParameterMap}" data-sly-unwrap> this will also work.

and also I have written some JS for fetching the two queryparameters and assigning it to some variable in JS itself and returning it in html.


In that way it was fixed.

Translate
Employee
Jan 16, 2018 2:15 PM UTC

Use this condition as below and let me know ,if it works fine.

<sly data-sly-test="${request.requestParameterMap}" data-sly-unwrap>

${request.requestParameterMap['test'][0].toString}

</sly>

Translate
krish1442
krish1442Author
Level 2
Jan 16, 2018 9:34 AM UTC

Currently we do have same code but its not working after installing CFP1 in 6.3..
It will work only when we have queryparameters in URL , otherwise its throwing an error but it was not happened before CFP1

Translate
kautuk_sahni
Employee
Jan 16, 2018 9:11 AM UTC

As mentioned by Ankur,

To access the parameter value, you can use ${request.requestParameterMap['test'][0].toString}.

Example: URL: http://server:port/xyz?test=hello

then output would be: hello

Reference point 12:- HTL introduction part 5: FAQ

-Kautuk

Translate
Kautuk Sahni
krish1442
krish1442Author
Level 2
Jan 16, 2018 8:52 AM UTC

Thanks..
I tried that but its not working after CFP1.
It will work only when you have query parameters in your URL, otherwise its throwing above error.
Its not working even when we are testing the condition using data-sly-test..

Translate
AnkurAhlawat-1
Level 6
Jan 15, 2018 1:47 PM UTC

Can you try   <sly data-sly-test.val=${request.requestParameterMap['value'][0].toString} />

Translate