Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Sling Model error, not injecting property

Avatar

Level 3

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.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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

View solution in original post

4 Replies

Avatar

Level 10

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....

Avatar

Level 3

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;

  }

}

Avatar

Level 10

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

Avatar

Correct answer by
Employee Advisor

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