Unable to iterate paragraph object in Sightly

Avatar

Avatar

rohitn62196663

Avatar

rohitn62196663

rohitn62196663

10-11-2016

I am trying to iterate a list of paragraphs(com.day.cq.wcm.foundation.Paragraph) using JAVA USE API and Sightly. However it displays an empty list in the 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;

View Entire Topic

Avatar

Avatar

rohitn62196663

Avatar

rohitn62196663

rohitn62196663

10-11-2016

Yes. The data is coming correctly in the backend. I am converting a component from JSP to Sightly and that is where I am seeig the error. I need the paragraph data so that I can use that as a path to include a new component.

 

Existing JSP code looks like this:

<%

ParagraphSystem parSys = ParagraphSystem.create(resource, slingRequest); for (Paragraph par: parSys.paragraphs()) { %> <sling:include resource="<%= par %>"/> <%}%>

Now in order to convert this in sightly, I created a list in backend and added the paragraphs to the list and then iterating them in the front end to include it new component. In order to do this first I am cross checking whether I am able to get the data or not. But its unable to read the data.