Sling Scripts cannot be called directly in CQ5. | Community
Skip to main content
New Participant
October 16, 2015
Solved

Sling Scripts cannot be called directly in CQ5.

  • October 16, 2015
  • 3 replies
  • 1071 views

Hi All,

I read the below :

Within Sling, scripts cannot be called directly as this would break the strict concept of a REST server; you would mix resources and representations.

If you call the representation (the script) directly you hide the resource inside your script, so the framework (Sling) no longer knows about it. Thus you lose certain features:

automatic handling of http methods other than GET, including:
POST, PUT, DELETE which are handled with a sling default implementation
the POST.jsp script in your sling:resourceType location
your code architecture is no longer as clean nor as clearly structured as it should be; of prime importance for large-scale development

I could not understand much on this. Any detailed explanation on this will be helpful.

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,

basically it's all about resources. You request a resource and internally sling uses a specific algorithm to determine the script which is used to render the resource in the format you request. Therefor you do not call a script and give the resource to render as paramter to it.
For details please see the Sling documentation to the script resolution algorithm [1]. With [2] there is another document available, which might be more readable.

Does this answer your question?

kind regards,
Jörg

 

[1] https://sling.apache.org/documentation/the-sling-engine/url-to-script-resolution.html
[2] http://dev.day.com/content/ddc/blog/2010/08/understanding_howsc.html

3 replies

smacdonald2008
New Participant
October 16, 2015

 WHen a request occurs - sling decides which script (under a node) to call based on coniditons. 

Watch this playback for more information on how sling determines which script to call: 

May session of AEM Ask the Community Experts

joerghoh
joerghohAccepted solution
Employee
October 16, 2015

Hi,

basically it's all about resources. You request a resource and internally sling uses a specific algorithm to determine the script which is used to render the resource in the format you request. Therefor you do not call a script and give the resource to render as paramter to it.
For details please see the Sling documentation to the script resolution algorithm [1]. With [2] there is another document available, which might be more readable.

Does this answer your question?

kind regards,
Jörg

 

[1] https://sling.apache.org/documentation/the-sling-engine/url-to-script-resolution.html
[2] http://dev.day.com/content/ddc/blog/2010/08/understanding_howsc.html

askdctmAuthor
New Participant
October 16, 2015

Hi,

I did go through the webinar, however could not relate it to the doubt mentioned above.