How to refer a sling model with in a sling servlet? | Adobe Higher Education
Skip to main content
Level 2
March 20, 2018
해결됨

How to refer a sling model with in a sling servlet?

  • March 20, 2018
  • 14 답변들
  • 13697 조회

I have a sling model which inject an OSGi service. The request parameter for the service call is configurable. This service request is also generated in the sling model. This will invoke an API call and process the result in the sling model. I need to invoke this sling model inside a sling servlet call because a click event should trigger this functionality. So is there a way to invoke a sling model from a sling servlet.

이 주제는 답변이 닫혔습니다.
최고의 답변: OlivBur

Which url do you use to execute your click request to your servlet?

It is Best Practice to register your serlvet with a resourceType and if needed some selector or extension. With this you simply then can call an url like this for example: /content/myweb/par/componentOne.html

Then in the Servlet you will have the current resource available with request.getResource(). From this you can easily read your authored data or also adapt it to some Sling model, etc.

14 답변

smacdonald2008
Level 10
March 24, 2018

You can read JCR data from servlet using Node API directly from servlet

Level 2
March 25, 2018

Thanks for your suggestion but it may need to include login credentials specific for each environment, right. I was just curious about whether a sling model can be referred from a sling servlet. As it is not possible, I'll look for a different approach that suits my requirements. Thank you once again.

OlivBur
OlivBur답변
Level 2
March 27, 2018

Which url do you use to execute your click request to your servlet?

It is Best Practice to register your serlvet with a resourceType and if needed some selector or extension. With this you simply then can call an url like this for example: /content/myweb/par/componentOne.html

Then in the Servlet you will have the current resource available with request.getResource(). From this you can easily read your authored data or also adapt it to some Sling model, etc.

Level 2
March 27, 2018

Thanks OlivBur for reminding me that. My servlet is already registered as resource type. I almost forgot about the getResource, my bad.