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

Level 9
June 21, 2022

@santoshsai Those paths are set in the dialog and no manipulation is done to the paths. The multi as in the original thread is referring to the root node or the multi node based on scenarios mentioned above [A] and [B]
Below code is exactly that returns the root node if multi is not available or multi node if it is ,when i print multi.path in html. There is no post construct.
Given the structure

carousel1/

      slides

      multi
if there is no multi node as a child node to carousel ,the controller.multi.path in html returns  the path to carousel1 else it returns path to multi.

My concern is  why it returns the carousel node path if no multi node is present.

Doing a @inject injects it as a child resource or should i specifically specify it as a child resource?

 

Hope this helps. 

 

@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
}

 


Trying with 
@Inject
@Optional
@ChildResource(name = "multi")
public Resource multi;

 

Weird this worked on 64 and fails on 6.5.12. Will update if i succeed , this will avert the boolean check as well

@santoshsai