3

We are trying a sample sling model implementation in AEM 6.0.

The sling model class without the imports is 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 being called in the 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 are getting the following error :

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

We have imported the taglib using following statement:

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

Initially, the 2.2.0 version of Apache Sling JSP Tag Library bundle was present. We also tried uploading the 2.2.4 version, but it didn't help.

Can somebody please guide if anything else is required for adaptTo tag to be available?

Mateusz Chromiński
  • 2,742
  • 4
  • 28
  • 45
iAMintoAEM
  • 71
  • 6
  • The taglib declaration is correct. Can you post the full JSP source code? Perhaps you are including other JSPs which 'shadow' this import with an older version – Robert Munteanu Aug 07 '15 at 13:22
  • According to the [documentation](https://sling.apache.org/documentation/bundles/sling-scripting-jsp-taglib.html), the `adaptTo` tag has been available since version _1.3_ so I wouldn't expect this to be the problem. Perhaps you're shadowing the namespace with something else as suggested above. Or maybe you've got something nasty cached in `/var/classes`. Have you tried forcing AEM to recompile the JSPs? – toniedzwiedz Aug 23 '15 at 19:58

1 Answers1

4

Stumbled across this while trying to help a coworker debug a similar issue. At first I was able to replicate this behavior (AEM 6.1) by copying the segment from the Doc page: <sling:adaptTo adaptable="${resource}" adaptTo="org.apache.sling.api.resource.ValueMap" var="myProps" />

What I found on my local was that our custom global.jsp file reference the old, pre-Granite version at /libs/foundation/global.jsp. Within that file I saw it had <%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %>. As a quick test I deleted the /1.0 at the end and refreshed the page and BAM, it worked.

Greg S
  • 41
  • 3