Problems when getting the index or count on data-sly-list | Community
Skip to main content
francisco_ribei
Level 6
October 16, 2015
Solved

Problems when getting the index or count on data-sly-list

  • October 16, 2015
  • 12 replies
  • 5715 views

Hi,

I'm using sightly with a Java class annotated with @Model.

And the class has a method that return a list with objects. Like List<CarouselPage> pages;

I can iterate over the list and get the object properties, but when I try ${itemList.count} or ${itemList.index} it throws an error:

Caused by: io.sightly.java.compiler.CompilerException: Compilation errors in apps/<mysite>/components/content/carousel/SightlyJava_carousel.java:
Line 79, column 4018 : Cannot invoke equals(boolean) on the primitive type long
    at io.sightly.java.compiler.SightlyCompileServiceImpl.compileJavaResource(SightlyCompileServiceImpl.java:187)
    at io.sightly.java.compiler.SightlyCompileServiceImpl.compileSource(SightlyCompileServiceImpl.java:132)

I thought it was a problem wiht List itself, then I tried returning the iterator instead of the List, but I got the same problem. 

But when I try with the iterator returned by currentPage.listChildren the index and cound works.

Did you guys already faced this problem?

Follow the code:

<ul data-sly-list="${currentPage.listChildren}"> <li>${itemList.index} - ${item.title}</li> </ul> <ol class="carousel-indicators" data-sly-list="${carousel.pages}"> <li data-target="#main-slider" data-slide-to="${itemList.index}" class=""></li> </ol>
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Feike_Visser1

With the attribute I mean data-slide-to="", instead of <li>${itemList.index}</li>

12 replies

francisco_ribei
Level 6
October 16, 2015

Hi Feike,

It doesn't. It has only String values.

Follow the code:

import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.models.annotations.Model; @Model(adaptables=SlingHttpServletRequest.class) public class CarouselPage { private String title; private String description; private String fileImage; private String path; public CarouselPage(String title, String description, String fileImage, String path) { this.title = title; this.description = description; this.fileImage = fileImage; this.path = path; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getFileImage() { return fileImage; } public void setFileImage(String fileImage) { this.fileImage = fileImage; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } @Override public String toString() { return "CarouselPage [title=" + title + ", description=" + description + ", fileImage=" + fileImage + ", path=" + path + "]"; } }
Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

Does your CarouselPage has a 'long' variable?

Can you change that to a 'Long'?

If the issue remains can you then show the code of your CarouselPage?