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>
Solved! Go to Solution.
Views
Replies
Total Likes
With the attribute I mean data-slide-to="", instead of <li>${itemList.index}</li>
Views
Replies
Total Likes
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?
Views
Replies
Total Likes
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 + "]"; } }
Views
Replies
Total Likes
Can you also share the other class you have with the @Model.
I have had a similar case, and it had to do that a @Inject property was of wrong type.
Views
Replies
Total Likes
BTW: Your carouselPage doesn't use any of the Sling-model functionalities, except @Model
Views
Replies
Total Likes
Follow the model class that is used on the sighlty:
import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.models.annotations.Model; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.day.cq.wcm.api.Page; import com.day.cq.wcm.commons.WCMUtils; import com.day.cq.wcm.foundation.List; @Model(adaptables=SlingHttpServletRequest.class) public class CarouselComponent { private static final Logger LOG = LoggerFactory.getLogger(CarouselComponent.class); @Inject protected SlingHttpServletRequest request; @Inject protected Page currentPage; protected Iterator<Page> pagesIterator; public java.util.List<CarouselPage> pages; @PostConstruct public void init() throws PathNotFoundException, RepositoryException { LOG.info("Init CarouselComponent"); List listComponent = new List(request); pagesIterator = listComponent.getPages(); pages = populatePages(); } /** * * @return * @throws PathNotFoundException * @throws RepositoryException */ public java.util.List<CarouselPage> populatePages() throws PathNotFoundException, RepositoryException { java.util.List<CarouselPage> pageList = new LinkedList<CarouselPage>(); if(pagesIterator != null) { while(pagesIterator.hasNext()) { LOG.info("Inside While"); Page page = pagesIterator.next(); Node jcrContent = WCMUtils.getNode(page.getContentResource()); Node imageNode = getImage(jcrContent); String fileImage = null; if(imageNode != null) { fileImage = imageNode.getProperty("fileReference").getValue().toString(); LOG.info("fileImage:" + fileImage); } CarouselPage carouselPage = new CarouselPage(page.getPageTitle(), page.getDescription(), fileImage, page.getPath()); pageList.add(carouselPage); } } LOG.info("pageList:" + pageList); return pageList; } protected Node getImage(Node node) { Node imageNode = null; try { LOG.info("Getting image from:" + node.getPath()); LOG.info("Getting the resolver"); ResourceResolver rs = request.getResourceResolver(); Resource r = rs.resolve(node.getPath() +"/image"); if(r != null) LOG.info("Resource:" + r); NodeIterator it = node.getNodes(); while(it.hasNext()) { LOG.info("Node:" + ((Node)it.next()).getName()); } imageNode = node.getNode("image"); } catch (PathNotFoundException e) { LOG.error("Error while retrieving node image", e); } catch (RepositoryException e) { LOG.error("Error while retrieving node image", e); } catch (Throwable e) { LOG.error("Error while retrieving node image", e); } return imageNode; } }
Views
Replies
Total Likes
Would also be able to share you sightly code snippet?
Let's find the issue :-)
Views
Replies
Total Likes
Thanks. Trying to reproducing now on AEM6+SP1
Views
Replies
Total Likes
Here is the sightly snippet:
The second itemList.index that throws the error.
<section id="main-slider" class="no-margin" data-sly-use.carousel="com.mycompany.models.CarouselComponent"> <div class="carousel slide"> <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> </div> </section><!--/#main-slider-->
Views
Replies
Total Likes
Found it....
We were looking at the wrong place, it was due to this:
data-slide-to="${itemList.index}"
Because the value is in attribute, Sightly tries to convert it to a boolean to check if the attribute need to be removed. That why the error: equals(boolean) on the primitive type long
If you replace it with this it is ok:
data-slide-to="${ '{0}' @ format=[itemList.index]}"
Views
Replies
Total Likes
Wow It worked
Thanks for your help.
I didn't understand very well the problem, what did you mean by the value is in attribute?
Att.
Views
Replies
Total Likes
With the attribute I mean data-slide-to="", instead of <li>${itemList.index}</li>
Views
Replies
Total Likes
Ahh!! got it!!!
Thanks you so much!!
Views
Replies
Total Likes