Getting an error when using the adaptTo Sling method when using Sling Models

In AEM 6.0 we are trying to use a sample line model.

The sling model class without import looks like this:

@Model(adaptables = Resource.class)
public class Header {   

    @Inject
    private String link;
    @Inject
    private String text;

    public String getLink() {
    return link;
    }
    public String getText() {
    return text;
    }

}

      

The sling model is called in jsp using the following lines of code

<sling:adaptTo adaptable="${resource}" adaptTo="com.mysite.models.Header" var="model"/>
<h2>${model.link}</h2>
<h2>${model.text}</h2> 

      

However, we get the following error:

No tag "adaptTo" defined in tag library imported with prefix "sling"

      

We imported taglib using the following statement:

<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling" %>

      

The Apache Sling JSP tag library version 2.2.0 was originally introduced. We also tried to download version 2.2.4 but it didn't help.

Can anyone ask for help if anything else is required for the adaptTo tag?

+3


source to share


1 answer


Stumbled upon this while trying to help a colleague debug a similar issue. I first managed to reproduce this behavior (AEM 6.1) by copying the segment in the Doc page : <sling:adaptTo adaptable="${resource}" adaptTo="org.apache.sling.api.resource.ValueMap" var="myProps" />



What I found on my local server was that our custom file was global.jsp

referencing an older version of pre-Granite at /libs/foundation/global.jsp

. Inside this file, I saw what it had <%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %>

. As a quick test, I removed /1.0

at the end and refreshed the page and BAM, it worked.

+3


source







All Articles