AEM - Sling model - Unable to @Inject on 6.5.12 | Community
Skip to main content
Level 9
June 21, 2022

AEM - Sling model - Unable to @Inject on 6.5.12

  • June 21, 2022
  • 1 reply
  • 1767 views

All,

 

On 64 the below logic resolved to the node multi n case of [A] or it returned empty in case of [B] but on 65 , this returns the parent node[B] if node multi is not found else it returns as in [A] that is expected. Tried @Named but didn't help. Please let me know if i am missing something

 

 

I want it to resolve to multi only. This was working on 64 and now we migrated to 6.5.12 and it is broken. 

 

<sly data-sly-use.carousel="com.test.aem.core.components.carouselController">

 

@Model(adaptables = Resource.class)
public class CarouselController {

@586265
@7392697
public Resource multi;

 

 

 

The content structure 

For [A] - with "multi" node's presence, ${carousel.multi.path} is the path to "multi" node

[A]

/content/X/..
      /group

        /slides

        /multi

 

For [B] - where "multi" node is missing,  ${carousel.multi.path} is the path to "group" node

[B]

The content structure is 

/content/X/..
      /group

        /slides

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SantoshSai
Community Advisor
Community Advisor
June 21, 2022

Hi @nitrohazedev ,

Have you tied with 

@SlingObject
@Optional
public Resource multi;

ignore if already!

Regards,

Santosh 

Santosh Sai
Level 9
June 21, 2022

Hi @santoshsai , thanks for the input, it did not help. I hadn't tried it per say until you brought it out but in vain
@SlingObject
@Optional

SantoshSai
Community Advisor
Community Advisor
June 21, 2022

@nitrohazedev Is it possible to pass piece of code from Model class? I wan't to see if is there any process with Resource multi variable.

Thats correct resource path will be exactly where current component is used. If your Resource is not pointing to a valid AEM Resource. You must make sure that you are referencing something in the JCR to which the model binds to.

In your multifield example here- the model binds to the products node in the dialog that represents the multi-field node.

@Model(adaptables = Resource.class)
public class CarouselController {

// Inject the multi node under the current node
@Inject
@Optional
public Resource multi;
// No need of a post construct as we don't have anything to modify after the
// model is constructed
}
Santosh Sai