RRN
RRN

Reputation: 81

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

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>

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.

Note: Paragraph is not a custom class, its the cq foundation class i.e. com.day.cq.wcm.foundation.Paragraph;

Upvotes: 0

Views: 183

Answers (1)

Ameesh Trikha
Ameesh Trikha

Reputation: 1712

If you look at the JavaDocs for the Paragraph the getType() returns an Enum which i guess can not be interpreted by HTL. What you could try is -

paragraphs.type.name

Upvotes: 1

Related Questions