Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Call Model Inside Service

Avatar

Avatar
Boost 10
Level 2
AD-Engineer
Level 2

Likes

10 likes

Total Posts

23 posts

Correct Reply

0 solutions
Top badges earned
Boost 10
Validate 1
Ignite 1
Give Back 3
Give Back
View profile

Avatar
Boost 10
Level 2
AD-Engineer
Level 2

Likes

10 likes

Total Posts

23 posts

Correct Reply

0 solutions
Top badges earned
Boost 10
Validate 1
Ignite 1
Give Back 3
Give Back
View profile
AD-Engineer
Level 2

28-05-2021

Hi,

We are trying to create a filter component (that filters results based on tags). Query should accept parent page from which the pages will be shown as a list. We got the value that is given as input on the component. We got it using Sling Model. We are trying to pass it to Service class, in order to pass it to Query. But, when we call the methods of model, all return null. Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

559 likes

Total Posts

676 posts

Correct Reply

194 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile

Avatar
Give Back 100
Level 10
asutosh_jena
Level 10

Likes

559 likes

Total Posts

676 posts

Correct Reply

194 solutions
Top badges earned
Give Back 100
Boost 500
Affirm 100
Ignite 1
Establish
View profile
asutosh_jena
Level 10

28-05-2021

Hi @AD-Engineer 

 

You can call the service class inside the Sling Model using below annotation where QueryResultsService is a custom service that is implemented to filter out the results based on the tags.

 

@OSGiService
private QueryResultsService queryService;

 Which one is returning null?

Answers (2)

Answers (2)

Avatar

Avatar
Boost 10
Level 2
AD-Engineer
Level 2

Likes

10 likes

Total Posts

23 posts

Correct Reply

0 solutions
Top badges earned
Boost 10
Validate 1
Ignite 1
Give Back 3
Give Back
View profile

Avatar
Boost 10
Level 2
AD-Engineer
Level 2

Likes

10 likes

Total Posts

23 posts

Correct Reply

0 solutions
Top badges earned
Boost 10
Validate 1
Ignite 1
Give Back 3
Give Back
View profile
AD-Engineer
Level 2

30-05-2021

Hi @asutosh_jena,

I do not want to access Service from Sling Model, but Sling Model from Service. Thanks!

Avatar

Avatar
Boost 10
Level 2
AD-Engineer
Level 2

Likes

10 likes

Total Posts

23 posts

Correct Reply

0 solutions
Top badges earned
Boost 10
Validate 1
Ignite 1
Give Back 3
Give Back
View profile

Avatar
Boost 10
Level 2
AD-Engineer
Level 2

Likes

10 likes

Total Posts

23 posts

Correct Reply

0 solutions
Top badges earned
Boost 10
Validate 1
Ignite 1
Give Back 3
Give Back
View profile
AD-Engineer
Level 2

28-05-2021

Hi @asutosh_jena 

Thanks for your reply!

I tried this one, but this returns null too.

The errorr: 

org.apache.sling.scripting.sightly.SightlyException: org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: Identifier com.project.core.models.Filter cannot be correctly instantiated by the Use API

 

Thanks!