简体   繁体   English

无法在Sightly中迭代段落对象

[英]Unable to iterate paragraph object in Sightly

I am trying to iterate a list of paragraphs(com.day.cq.wcm.foundation.Paragraph) using JAVA USE API and Sightly. 我正在尝试使用JAVA USE API和Sightly迭代段落列表(com.day.cq.wcm.foundation.Paragraph)。 It is able to get the paragraphs in the backend. 它可以在后端获取段落。 However its unable to read that and display it in front end. 但是,它无法读取并在前端显示它。

Below is the code: 下面是代码:

JAVA: 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: 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>

I am trying to get the type of paragraph from the foundation paragraph class. 我试图从基础段落类中获取段落的类型。 But its able to identify the size and iterating 'n' times but its not able to display the value. 但是它能够识别大小并迭代“ n”次,但无法显示该值。

Note: Paragraph is not a custom class, its the cq foundation class ie com.day.cq.wcm.foundation.Paragraph; 注意:段落不是自定义类,它是cq基础类,即com.day.cq.wcm.foundation.Paragraph;

If you look at the JavaDocs for the Paragraph the getType() returns an Enum which i guess can not be interpreted by HTL. 如果您查看该Paragraph的JavaDocs,则getType()返回一个Enum,我猜它不能由HTL解释。 What you could try is - 您可以尝试的是-

paragraphs.type.name

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

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