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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Doubt and Solution

Avatar

Level 1

I have question like I have a slingmodel XYZ and created a component and dialog for sling model XYZ.
From the same component dialog how to inject sling model ABC without using Mulitfield in dialog.
So how to design dialog and sling model for this purpose.

@Model(adaptables = "Resource.class", defaultInjectionStrategy = DefaultInjectionStrategy.Optional)
public class Xyz {
      @getter

     @inject
     private String A;

     @getter
    @inject
    Private ABC bclass;
}

@Model(adaptables = "Resource.class", defaultInjectionStrategy = DefaultInjectionStrategy.Optional)
public class ABC {

      

     @getter

     @inject
     private String C;

 

      @getter

     @inject
     private String D;
}



1 Accepted Solution

Avatar

Correct answer by
Level 7
2 Replies

Avatar

Correct answer by
Level 7

Avatar

Level 8
@Model(adaptables = "Resource.class", defaultInjectionStrategy = DefaultInjectionStrategy.Optional)
public class Xyz {
      @getter

     @inject
     private String A;

   @Self
    Private ABC bclass;
}

@Model(adaptables = "Resource.class", defaultInjectionStrategy = DefaultInjectionStrategy.Optional)
public class ABC {

      

     @getter

     @inject
     private String C;

 

      @getter

     @inject
     private String D;
}

Using the @Self annotation, you will be able to achieve this.

@Self Annotation - this annotation injects the adaptable object itself. If the @Self annotation is present it is tried to adapt the adaptable to the field type.

Reference Details: https://taradevko.com/aem/sling-models-self-annotation/

Hope this helps!

Thanks