Expand my Community achievements bar.

SOLVED

Sling Delegation Pattern not working for Breadcrumb Commerce Component

Avatar

Level 1

We had a requirement wherein it was required for us to do the customization of OOTB Breadcrumb CIF component. As OOTB Breadcrumb CIF component internally inherits Breadcrumb Core component, it was using Sling Delegation Pattern for the same. 

But now, when we tried to using the same logic and use Delegation Pattern for our custom breadcrumb component which inherits OOTB Breadcrumb CIF component, it has started to give us a Null object for the same. 

Below are the levels of inheritance we are following:

CustomBreadcrumbImpl <- CIF BreadcrumbImpl <- WCM BreadcrumbImpl

 

Below is the code snippet through which I am trying to access the object.

import com.adobe.cq.commerce.core.components.models.breadcrumb.Breadcrumb;

@Model(adaptables = SlingHttpServletRequest.class, adapters = { Breadcrumb.class,
CustomBreadcrumb.class }, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL, resourceType = "project/components/commerce/breadcrumb")
public class CustomBreadcrumbImpl implements CustomBreadcrumb {

@Deleted Account
@Via(type = ResourceSuperType.class)
private Breadcrumb customBreadcrumb;

 

Has anyone faced any such issues? Any idea how we can manage these kind of issues where three layers of inheritance is observed? 

Help would be much appreciated. Thanks. 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Jatin-Verma 

Try to use Lombok @Delegate for Sling Model Delegation. Sample usage - https://www.initialyze.com/blog/2020/11/simplify-extending-sling-models-with-lombok/

 

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

Hi @Jatin-Verma 

Try to use Lombok @Delegate for Sling Model Delegation. Sample usage - https://www.initialyze.com/blog/2020/11/simplify-extending-sling-models-with-lombok/

 

Avatar

Level 1

Hi @Vijayalakshmi_S , Thank you for your response. I have tried implementing @Delegate for Sling model as mentioned by you but still I am not able to extend CIF Core Breadcrumb Component.

 

import com.adobe.cq.commerce.core.components.models.breadcrumb.Breadcrumb;

 

@Delegate(types = Breadcrumb.class)
@Self@Via(type = ResourceSuperType.class)
private Breadcrumb customBreadcrumb;

 

Please suggest. Thanks!

Avatar

Community Advisor

@hanish_imandi2 

Could you please let know the issue - is the customBreadcrumb reference is null or you have issue in extending the methods 

Avatar

Community Advisor

If your project specific breadcrumb is inheriting from this CIF breadcrumb component - core/cif/components/structure/breadcrumb/v1/breadcrumb (which in turns inherit from Core WCM breadcrumb), then the Model that we should be providing custom implementation for is com.adobe.cq.wcm.core.components.models.Breadcrumb and not com.adobe.cq.commerce.core.components.models.breadcrumb.Breadcrumb

 

Could you please let know the need for customization.