Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Error using jstl inside component jsp

chetanvajre2014
Level 5
Level 5

I'm using this simple tag

<c:set var="content" value="${sling:getResource(resourceResolver,/content/dam/imf/public/sampleicons)}" />

Getting an error

The function getResource cannot be located with the specified prefix

 

Complete jsp:

<%--

  Directory Browser component.

  Lists all resources in the directory

--%><%
%><%@include file="/libs/foundation/global.jsp"%>
<%
%><%@page session="false" %><%
%><%
    // TODO add you code here
%>

<sling:defineObjects/>
<%
String url ="/content/dam/imf/public/sampleicons";
%>
This component lists all in the directory
<c:set var="content" value="${sling:getResource(resourceResolver,url)}" />

 

Reference used:

https://sling.apache.org/documentation/bundles/sling-scripting-jsp-taglib.html

1 Accepted Solution
kunal23
Correct answer by
Level 10
Level 10

You can check the version of taglib in the following bundle jar - org.apache.sling.scripting.jsp.taglib. In AEM 6.1, three versions of taglib are included - 1.0,1.1,1.2 and 1.4 with URI - http://sling.apache.org/taglibs/sling. The TLD files are in META-INF folder in the jar file.  

I have tested the following code in 6.1 and it works fine- 

<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling" %> <%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %> <cq:defineObjects /> <c:set var="content" value="${sling:getResource(resourceResolver,'/content')}" />

View solution in original post

12 Replies
Lokesh_Shivalingaiah
Community Advisor
Community Advisor

why dont you try with this

<sling:defineObjects> has directly the sling tag libraries to use like below

<sling:getResource var="content" path="<url>" />

chetanvajre2014
Level 5
Level 5

Getting the same

Interesting, seems like for some reason the taglib isn't loading either that specific implementation. IF you look at my code, I have used slign:definobjects
    

Error during include of component '/apps/imftgsik/components/directorybrowser'

Error Message:

org.apache.sling.api.scripting.ScriptEvaluationException: org.apache.sling.scripting.jsp.jasper.JasperException: /apps/imftgsik/components/directorybrowser/directorybrowser.jsp(20,0) No tag "getResource" defined in tag library imported with prefix "sling"
chetanvajre2014
Level 5
Level 5

Global.jsp has this defined

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

 

We are using 5.6.1

smacdonald2008
Level 10
Level 10

I have not seen an issue with JSP - Standard Tag Libraries and AEM. For example - see this AEM Community article: 

https://helpx.adobe.com/experience-manager/using/jstl.html

kunal23
Level 10
Level 10

As per the documentation, the getResource method is available since taglib version 1.3. The taglib URI imported in global.jsp is 1.0 and thats why the method is not working for you. 

To solve this problem, do the following- 

  1. Override global.jsp under apps and change the Sling taglib URI to the following- http://sling.apache.org/taglibs/sling (As per documentation - All releases from 1.3 onward are expected to use the URI http://sling.apache.org/taglibs/sling to ensure ease of upgrading to newer versions of the Taglib.)
  2. In your JSP include the global.jsp from /apps location and not from /libs. 
  3. In the getResource method the resource path should be passed as String (The quotations are missing in your syntax). <c:set var="content" value="${sling:getResource(resourceResolver,'/content/dam/imf/public/sampleicons')}" /> 
chetanvajre2014
Level 5
Level 5

Kunal

That could be it! Quick question, in 6.1, what version is included by default?

chetanvajre2014
Level 5
Level 5

Kunal,

I think I had tried that, but getting this error:

xception: /apps/imftgsik/components/directorybrowser/directorybrowser.jsp(1,1) The absolute uri: http://sling.apache.org/taglibs/sling/1.3 cannot be resolved in either web.xml or the jar files deployed with this application

Do we need to update one of the core jar files?

kunal23
Correct answer by
Level 10
Level 10

You can check the version of taglib in the following bundle jar - org.apache.sling.scripting.jsp.taglib. In AEM 6.1, three versions of taglib are included - 1.0,1.1,1.2 and 1.4 with URI - http://sling.apache.org/taglibs/sling. The TLD files are in META-INF folder in the jar file.  

I have tested the following code in 6.1 and it works fine- 

<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling" %> <%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %> <cq:defineObjects /> <c:set var="content" value="${sling:getResource(resourceResolver,'/content')}" />