0

I have created a Java class method getmyPages() which returns iterator<Page>. Now in HTML page I am able to instantiate the class and access other properties of this class.

However I want to iterate over this iterator the way currentPage.listChildren works.....

Since currentPage.listChildren returns iterator<Page> I am also returning same.

However I am not able to ...... the HTML tag in which I am printing this comes out empty.

Bertrand Delacretaz
  • 6,100
  • 19
  • 24
user4052951
  • 1
  • 1
  • 1
  • 2
  • Can you post your sightly code as well, this would help understand your problem. Though it could be that only lists are alowed, I never tried it with an iterator. You can convert an Iterator to a List with the answers from this question: http://stackoverflow.com/questions/10117026/convert-iterator-to-arraylist – Thomas Dec 08 '14 at 14:51

3 Answers3

6

You can use data-sly-list attribute to loop over an iterator. Here's an excerpt from Feike Visser's Sightly tutorials :

<ul data-sly-list.child="${currentPage.listChildren}">
  <li>${child.title}</li>
</ul>

data-sly-unwrap attribute can be used to prevent enclosing tag of the loop from being part of the final mark up

<ul data-sly-list.child="${currentPage.listChildren}" data-sly-unwrap>
  <li>${child.title}</li>
</ul>

Link to the tutorials : http://blogs.adobe.com/experiencedelivers/experience-management/sightly-intro-part-1

Documentation of data-sly-list : link

Sharath Madappa
  • 3,393
  • 1
  • 24
  • 41
-1

java class public class TabControl extends WCMUse {

@Override
public void activate() throws Exception {
    // nothing to be done here in this case
}

  public Iterator<Map<String, Object>> getTabTitles(){

      final I18n i18n = new I18n(getRequest());
      List<Map<String, Object>> infos = new LinkedList<Map<String,Object>>();
      String[] tabTitles = getProperties().get("tabs", String[].class);
   if (tabTitles == null || tabTitles.length == 0) {
         tabTitles = new String[1];
         tabTitles[0] = i18n.get("Tab One from sightly");
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("tabTitle",  tabTitles[0]);
         infos.add(map);
   }else if(tabTitles.length > 0){
       for (String tab : tabTitles) {
           Map<String, Object> map = new HashMap<String, Object>();
           map.put("tabTitle",  tab);
           infos.add(map);   
    }
   }
   return  infos.iterator();
}



 }
shankar
  • 57
  • 1
  • 6
-1

In my Java code I'm returning a List then using Sightly

Java Class

public class ListFilesUse extends WCMUsePojo{

private String name;

private List<TrFile> files = new ArrayList<TrFile>();

Sightly

<div data-sly-use.test="apps.ecolorado.components.sharedcontent.ListFilesUse">
    ${test.name}
    <ul data-sly-list.child="${test.files}">
        <li>${child.fileName}</li>
    </ul>
</div>

And this is working in progress code.

Matt Swezey
  • 379
  • 3
  • 11
  • 27