Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Getting error in using POJO class with HTL code.

Avatar

Level 3

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@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"

View solution in original post

9 Replies

Avatar

Community Advisor

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.

Avatar

Level 3
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

Avatar

Level 3
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.

Avatar

Community Advisor

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

Avatar

Level 3
<div sly data-sly-use .demobeanObj="com.packagename.demoUse" data-sly-test="${demobeanObj}">

Avatar

Community Advisor

What is the sling model package defined in POM?

e.g. https://github.com/arunpatidar02/aem63app-repo/blob/master/java/POMs/core-pom.xml

 

<plugin>
				<groupId>org.apache.felix</groupId>
				<artifactId>maven-bundle-plugin</artifactId>
				<extensions>true</extensions>
				<configuration>
					<instructions>
						<!-- Import any version of javax.inject, to allow running on multiple 
							versions of AEM -->
						<Import-Package>javax.inject;version=0.0.0,*</Import-Package>
						<Sling-Model-Packages>
							com.aem64.core
						</Sling-Model-Packages>
					</instructions>
				</configuration>
			</plugin>

 

Are you creating sling model inside this package?

 

 



Arun Patidar

Avatar

Level 3
Where or how do we check sling model package defined in POM? Guide please.

Avatar

Correct answer by
Community Advisor

@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"