Accessing SlingServlet Data into SlingModel | Community
Skip to main content
Level 2
Mar 25, 2022 10:47 AM UTC
Solved

Accessing SlingServlet Data into SlingModel

Hi All,

I have created Search Servlet  and as per the requirement I need to track search data like search count ,search result.

so for that I have created Sling Model for Analytics Tracking of current page data and For that Sling Model I need search data as well.

does anyone worked on same type of requirement.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
BrettBirschbach
BrettBirschbachAccepted solution
New Participant
Mar 25, 2022 9:24 PM UTC

If you are running server-side code to push this information over to Analytics or some other back end system, then I would agree with Brian's post here.  Sling models are generally for representing a JCR resource that correlates with a page component.  An OSGi service is going to provide you access to all of the same contexts that would be applicable to your task, and would be easier to leverage from your search servlet.

 

However, if you're looking for Analytics to pick this data up from the front end web page (similar to other Analytics data), it would be great to simply push this context into the Analytics datalayer.  Rather than using a servlet for search results, you can create a Sling Model for your "search_results" component - that sling model could A) execute the search and then B) update the datalayer with the data to by picked up by Analytics.

 

3 replies

BrettBirschbach
BrettBirschbachAccepted solution
New Participant
Mar 25, 2022 9:24 PM UTC

If you are running server-side code to push this information over to Analytics or some other back end system, then I would agree with Brian's post here.  Sling models are generally for representing a JCR resource that correlates with a page component.  An OSGi service is going to provide you access to all of the same contexts that would be applicable to your task, and would be easier to leverage from your search servlet.

 

However, if you're looking for Analytics to pick this data up from the front end web page (similar to other Analytics data), it would be great to simply push this context into the Analytics datalayer.  Rather than using a servlet for search results, you can create a Sling Model for your "search_results" component - that sling model could A) execute the search and then B) update the datalayer with the data to by picked up by Analytics.

 

Translate
BrianKasingli
New Participant
Mar 25, 2022 4:53 PM UTC

As a best practice to enforce re-usability, Maybe you can extract the business logic from the servlet into an OSGI service, so that all of your OSGI components can be using the same service. 

Translate
Kiran_Vedantam
New Participant
Mar 25, 2022 12:52 PM UTC

Hi @savi50,

 

You can inject servlets like this

 

@Inject private List<Servlet> servlets;

 

Thanks,

Kiran Vedantam.

Translate