Expand my Community achievements bar.

SOLVED

Any ideal use-case of injecting servlet in Sling Model ?

Avatar

Level 2
Any ideal use-case of injecting servlet in Sling Models ? @Model(adaptables=SlingHttpServletRequest.class)public class MyModel {@Inject@Filter("(paths=/bin/something)")private List<Servlet> servlets;}

Ref. :-https://sling.apache.org/documentation/bundles/models.html 

1 Accepted Solution

Avatar

Correct answer by
Level 10

According to the docs - you can use this annotation to filter OSGi injections "OSGi injection can be filtered"

However - i am not finding use cases or examples with Sling Models that make use of this feature. 

Here is another code example of SLing Models (-but it does not use @Filter)

https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/bundle/src/main/java/com/ad...

View solution in original post

7 Replies

Avatar

Level 9

What's your point?. Why would you use servlet in SlindModel?.

Jitendra

Avatar

Level 2

Yes, reason being calling servlet methods do not makes much sense.

       May be I am missing something here in case of servlet.

        Injecting any other service seems reasonable though.

Avatar

Level 9

  By design, Servlets are not mean to be treated like services. Servlet technology is being used for communication between client & server over the HTTP protocol.

Sunil Chowdhary wrote...

Yes, reason being calling servlet methods do not makes much sense.

       May be I am missing something here in case of servlet.

        Injecting any other service seems reasonable though.

 

Avatar

Level 2

Thanks for your reply.

Went through the mentioned article, but still not able to get the use of below code available at

https://sling.apache.org/documentation/bundles/models.html 

@Inject@Filter("(paths=/bin/something)")private List<Servlet> servlets;

Avatar

Correct answer by
Level 10

According to the docs - you can use this annotation to filter OSGi injections "OSGi injection can be filtered"

However - i am not finding use cases or examples with Sling Models that make use of this feature. 

Here is another code example of SLing Models (-but it does not use @Filter)

https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/bundle/src/main/java/com/ad...