Getting error in using POJO class with HTL code.

Avatar

Avatar

ShagunMalik

Avatar

ShagunMalik

ShagunMalik

07-01-2021

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.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Anudeep_Garnepudi

MVP

Avatar

Anudeep_Garnepudi

MVP

Anudeep_Garnepudi
MVP

20-02-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"

Answers (2)

Answers (2)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

882

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

882
Arun_Patidar
MVP

07-01-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.

Avatar

Avatar

SureshDhulipudi

MVP

Avatar

SureshDhulipudi

MVP

SureshDhulipudi
MVP

07-01-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.

ShagunMalik
package com.community.aem.core; /** * The Class HeroTextBean. */ public class HeroTextBean { /** The heading text. */ private String headingText; /** The description. */ private String description; /** * @Return the headingText */ public String getHeadingText() { return headingText; } /** * @Param headingText the headingText to set */ public void setHeadingText(String headingText) { this.headingText = headingText; } /** * @Return the description */ public String getDescription() { return description; } /** * @Param description the description to set */ public void setDescription(String description) { this.description = description; } } This is the code I used of help.adobe for creating my code
ShagunMalik
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; @Override 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.