Expand my Community achievements bar.

SOLVED

Doubt and Solution

Avatar

Level 2

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
Community Advisor
2 Replies

Avatar

Correct answer by
Community Advisor

Avatar

Community Advisor
@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 @Deleted Account annotation, you will be able to achieve this.

@Deleted Account Annotation - this annotation injects the adaptable object itself. If the @Deleted Account 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