Getting error in using POJO class with HTL code. | Community
Skip to main content
Level 3
January 7, 2021
Solved

Getting error in using POJO class with HTL code.

  • January 7, 2021
  • 3 replies
  • 2771 views

I was trying to take dialog values from AEM component and then map it to POJO class to retrieve data from POJO class but getting error:

org.apache.sling.api.slingexception: Cannot get DefaultSlingScript: No use provider could resolve identifier ....... 

Please help.

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 Anudeep_Garnepudi

@shagunmalik 

Package and Class names that referred  in HTL are case sensitive.

If your Use class fully qualified name is com.yourpackage.DemoUse then your HTL file should be like

<sly data-sly-use.demoUse="com.yourpackage.DemoUse"> .... </sly>

You are referring as data-sly-use.demoUse="com.yourpackage.demoUse"

3 replies

SureshDhulipudi
Community Advisor
Community Advisor
January 7, 2021

Can you provide your POJO class?

If you are using Sling Model, use the correct annotations and give the DEFAULT strategy options.

If any one of the node/property is null / empty, you will see this error.

Level 3
January 8, 2021
package com.community.aem.core; import com.adobe.cq.sightly.WCMUsePojo; import com.day.cq.search.PredicateGroup; import com.day.cq.search.Query; import com.day.cq.search.QueryBuilder; import com.day.cq.search.result.SearchResult; import com.day.cq.tagging.Tag; import com.day.cq.tagging.TagManager; import com.community.aem.core.HeroTextBean; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import javax.jcr.Node; import javax.jcr.Session; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ValueMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class HeroTextComponent extends WCMUsePojo { /** The hero text bean. */ private HeroTextBean heroTextBean = null; @9944223 public void activate() throws Exception { heroTextBean = new HeroTextBean(); String heading; String description ; //Get the values that the author entered into the AEM dialog heading = getProperties().get("heading", ""); description = getProperties().get("description",""); heroTextBean.setHeadingText(heading); heroTextBean.setDescription(description); } public HeroTextBean getHeroTextBean() { return this.heroTextBean; } } And this is POJO class i used.
arunpatidar
Community Advisor
Community Advisor
January 7, 2021

The issue could be with HTL data-sly-use statement. data-sly-use can only have Model/WCMUsePojo type

e.g. https://github.com/arunpatidar02/aem63app-repo/blob/master/java/ClientLibsModel.java

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/DisableEditModel.java

 

If you will just call POJO from htl, then it will not work.

Arun Patidar
Level 3
January 8, 2021
<div sly data-sly-use .demobeanObj="com.packagename.demoUse" data-sly-test="${demobeanObj}">
Anudeep_Garnepudi
Community Advisor
Anudeep_GarnepudiCommunity AdvisorAccepted solution
Community Advisor
February 20, 2021

@shagunmalik 

Package and Class names that referred  in HTL are case sensitive.

If your Use class fully qualified name is com.yourpackage.DemoUse then your HTL file should be like

<sly data-sly-use.demoUse="com.yourpackage.DemoUse"> .... </sly>

You are referring as data-sly-use.demoUse="com.yourpackage.demoUse"

AG