Expand my Community achievements bar.

Adobe Summit 2025: AEM Session Recordings Are Live! Missed a session or want to revisit your favorites? Watch the latest recordings now.
SOLVED

Issue with component and sling model

Avatar

Level 1

I am working on a component that uses a Sling Model and HTL, but the CTA link is not rendering on the page. Below is the code

Sling Model

@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class BannerModel {

    @ValueMapValue
    private String title;

    @ValueMapValue
    private String ctaText;

    @ValueMapValue
    private String ctaLink;

    public String getTitle() {
        return title;
    }

    public String getCtaText() {
        return ctaText;
    }

    public String getCtaLink() {
        return ctaLink;
    }
}

 banner.html

<div data-sly-use.model="com.techinnovia.core.models.BannerModel">
    <h1>${model.title}</h1>
    <a href="${model.ctaLink}">${model.ctaText}</a>
</div>

The component renders title and ctaText fine, but ctaLink always shows as null. No errors in logs.
What could be wrong here?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Luca_Moreau,

There might be few things you could double check:

  • Check if your HTL is expecting the model to adapt from a SlingHttpServletRequest, and may be your model uses Resource, in this case it won't adapt correctly.
  • Check if dialog field is saving properly - make sure the dialog field uses name="./ctaLink"
  • If name mismatch in between JCR and Java - in this case it won't be injected automatically.
    eg. If it’s saved as cta_link, but your model field is ctaLink
    @ValueMapValue(name = "cta_link")
    private String ctaLink;

hope this helps!


Santosh Sai

AEM BlogsLinkedIn


View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @Luca_Moreau,

There might be few things you could double check:

  • Check if your HTL is expecting the model to adapt from a SlingHttpServletRequest, and may be your model uses Resource, in this case it won't adapt correctly.
  • Check if dialog field is saving properly - make sure the dialog field uses name="./ctaLink"
  • If name mismatch in between JCR and Java - in this case it won't be injected automatically.
    eg. If it’s saved as cta_link, but your model field is ctaLink
    @ValueMapValue(name = "cta_link")
    private String ctaLink;

hope this helps!


Santosh Sai

AEM BlogsLinkedIn