Frage

I am creating a JSP in Apache Sling, where I use a scriplet to retrieve a list of objects, which I then want to iterate over using JSTL. However, with the code below, I do not see any of my results within JSTL. I can use JSTL (

The important pieces:

<%
    AppLinkService appLinkSvc = new AppLinkService(); 
    String userId = "sean"; //TODO get from request

    List<AppLink> links = appLinkSvc.getAppLinksFromWebService(userId);
    pageContext.setAttribute("appLinkList", links);
%>
<br/>
<br/>

<c:if test="${empty appLinkList}">
    <h1>You do not have any apps.</h1>
</c:if>
<c:if test="${not empty appLinkList}">
    <c:forEach items="${appLinkList}" var="link">
        <h3>
            <a href='<c:out value="${link.linkUrl}"/>'> 
                <c:out value="${link.appName}" /> 
            </a>
        </h3>
    </c:forEach>
</c:if>

I know that all of my imports are correct (I worked through all of those errors), but now I cannot access the objects. I have this same piece of code (with imports, etc.) working in a simple Tomcat web app, but I know things are different in Apache Sling. It seems as though pageContext does not work the same in the Sling world.

What am I missing?

Thanks, Sean

War es hilfreich?

Lösung

the code looks correct to me and should just work fine. Have you tried if the your links list does contain any objects? Try to access it like

<h1>Size is <%= links.size()%></h1>

HTH, (c)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top