无法在Sightly中迭代段落对象

时间:2016-11-10 18:34:16

标签: java aem sightly htl

我正在尝试使用JAVA USE API和Sightly迭代段落列表(com.day.cq.wcm.foundation.Paragraph)。它能够在后端获得段落。但是它无法读取并在前端显示它。

以下是代码:

JAVA:

public class AnchorList extends WCMUsePojo{

    private List<Paragraph> paragraphs;

    public List<Paragraph> getParagraphs() {
        return paragraphs;
    }

    public void setParagraphs(List<Paragraph> paragraphs) {
        this.paragraphs = paragraphs;
    }

    public void activate() throws Exception{

        paragraphs = new LinkedList<Paragraph>();
        Resource resource = getResource();

        SlingHttpServletRequest slingRequest = getRequest();

        ParagraphSystem parSys = ParagraphSystem.create(resource, slingRequest);

        for (Paragraph par: parSys.paragraphs()) {
            paragraphs.add(par);
        }
    }
}

HTML:

<div data-sly-use.anchorList="AnchorList" data-sly-unwrap>
    <div data-sly-list.paragraphs="${anchorList.paragraphs}" data-sly-unwrap>
       Para Type is: ${paragraphs.getType}
    </div>
</div>

我试图从基础段落类中获取段落类型。但它能够识别尺寸并迭代“&#39; n&#39;时间,但无法显示价值。

注意:段落不是自定义类,它是cq基础类,即com.day.cq.wcm.foundation.Paragraph;

1 个答案:

答案 0 :(得分:1)

如果你查看Paragraph的JavaDocs,getType()会返回一个枚举,我想这是不能被HTL解释的。您可以尝试的是 -

paragraphs.type.name