简体   繁体   English

在Apache Sling中访问JSTL中的pageContext变量

[英]access pageContext variables in JSTL within Apache Sling

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. 我正在Apache Sling中创建一个JSP,在这里我使用scriplet来检索对象列表,然后我想使用JSTL进行迭代。 However, with the code below, I do not see any of my results within JSTL. 但是,使用下面的代码,我在JSTL中看不到任何结果。 I can use JSTL ( 我可以使用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. 我在一个简单的Tomcat Web应用程序中也有同样的代码(带有导入等),但是我知道Apache Sling的情况有所不同。 It seems as though pageContext does not work the same in the Sling world. 似乎pageContext在Sling世界中无法正常工作。

What am I missing? 我想念什么?

Thanks, Sean 谢谢,肖恩

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) HTH,(c)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM