Sling Model error, not injecting property | Community
Skip to main content
Level 3
November 8, 2017
Solved

Sling Model error, not injecting property

  • November 8, 2017
  • 4 replies
  • 6368 views

Here is the warning...

08.11.2017 08:46:03.433 *WARN*

org.apache.sling.models.impl.injectors.ResourcePathInjector Could not retrieve resource at path NOT_SELECTED for field bottomMargin. Since it is required it won't be injected.

here is the groovy code:

@Component(value="Thumbnail",tabs = [@Tab(title = "General"), @Tab(title = "Advanced"), @Tab(title = "Override")],group="Basic")

@Model(adaptables=Resource,defaultInjectionStrategy=DefaultInjectionStrategy.OPTIONAL)

@Slf4j
class Thumbnail implements BottomMargin {

....

@Inject
Margin bottomMargin

...

}

Margin is an enum and NOT_SELECTED is the correct value.

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

This simply means that there is no property/resource called "NOT_SELECTED".

4 replies

smacdonald2008
Level 10
November 8, 2017

For starters - here you are using @Component and @Model annotations.

Check this doc - @Component is not a sling model annotation-  never seen them used together - not sure if that is valid.,

Apache Sling :: Sling Models

2nd - looks like you are trying to use Sling Model to inject node/props - this message indicates that the resource cannot be found at the JCR location.

"Could not retrieve resource at path"

If you want to use JCR node/props and inject them into data members with the @inject annotation - make sure that the nodes are part of the JCR location. See this example --

Scott's Digital Community: Creating Adobe Experience Manager 6.3 Sling Model Components

We successfully inject JCR node properties using @inject.  You can get a resource on which to base the sling model like this:

Resource resource = resolver.getResource("/content/testsling/slingmodel");

Hope this helps....

bfvaughnAuthor
Level 3
November 9, 2017

Sorry, I should have included the imports:

import com.citytechinc.cq.component.annotations.Component

import org.apache.sling.models.annotations.Model

So the wierd part is that NOT_SELECTED is the value for the property bottomMargin.

The property bottomMargin in an enum defined below.

public enum Margin {

   @Option(text = "Not Selected")

   NOT_SELECTED("")

  private String cssClass;

  private Margin(String cssClass) {

   this.cssClass = cssClass;

  }

}

smacdonald2008
Level 10
November 9, 2017

Are you trying to bind part of your model to JCR nodes located in the repository?

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
November 9, 2017

This simply means that there is no property/resource called "NOT_SELECTED".