Error while using data-sly-use to call Java class method | Community
Skip to main content
Level 4
June 17, 2020
Solved

Error while using data-sly-use to call Java class method

  • June 17, 2020
  • 2 replies
  • 2920 views

I am getting below error while using data-sly-use to call Java class method. what can be the issue ? any configuration issue ?

 

17.06.2020 01:37:28.281 *ERROR* [0:0:0:0:0:0:0:1 [1592372248213] GET /content/we-retail/us/en/sample.html HTTP/1.1] com.day.cq.wcm.core.impl.WCMDeveloperModeFilter Error during include of SlingRequestPathInfo: path='/content/we-retail/us/en/sample/jcr:content/root/responsivegrid/customcomponent', selectorString='null', extension='html', suffix='null'
org.apache.sling.api.SlingException: Cannot get DefaultSlingScript: No use provider could resolve identifier mycomponent
at org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:510) [org.apache.sling.scripting.core:2.0.56]
at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:552) [org.apache.sling.engine:2.6.18]
at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:44) [org.apache.sling.engine:2.6.18]
at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:82) [org.apache.sling.engine:2.6.18]

 

HTL component - 

 

<div data-sly-use.titleobj="mycomponent">
<h1>${titleobj.myTitle}</h1>
</div>

 

 

java class

mycomponent.java

 

import com.adobe.cq.sightly.WCMUsePojo;

public class mycomponent extends WCMUsePojo
{

private String myTitle;

@9944223
public void activate()
{
myTitle = "My Project" + getCurrentPage().getTitle();
}

public string getmyTitle()
{
return myTitle;
}

}

 

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 VeenaVikraman

@sonuk85184451 I read from the comments that you have your Java class in the same folder. This error clearly says that the Java class is not available. In your case it can be because that the Java Class is not compiled properly. If you see that your Java Class name is in small letters. As per Java standards and compiler , you need your Class name to start with Capital case. This will compile your Java classes properly and this issue should get resolved I believe. Please change your Java class name to MyComponent.java and test this

 

Disclaimer:- I am not 100% sure on this since I have never used Java class inside component. but give it a try 😉 and let us know

 

Side note:- I would recommend always writing Sling Models rather than writing it inside the component folder itself. 

 

Veena ✌

 

2 replies

Nupur_Jain
Adobe Employee
Adobe Employee
June 17, 2020

Hi @sonuk85184451 ,

 

you have used mycomponent.java class as
<div data-sly-use.titleobj="mycomponent">
when you specify java class without its package name, it means the java class is expected to be present in the same folder where your HTL file is present.

Looking at the exception you are getting, it is clear the class is not present in the same folder of your component . You have to specify your class with package name.

For ex: if class is present in package com.myproject.mymodels.mycomponent, then, the use include should be 

<div data-sly-use.titleobj="com.myproject.mymodels.mycomponent">

 

You can refer https://docs.adobe.com/content/help/en/experience-manager-htl/using/htl/use-api-java.html for more details on where you can create your java class and how to call it in HTL.

 

Thanks,

Nupur

 

Level 4
June 17, 2020

Hi @nupur_jain - thanks for responding. component.java is in same folder only . 

 

 

VeenaVikraman
Community Advisor
VeenaVikramanCommunity AdvisorAccepted solution
Community Advisor
June 17, 2020

@sonuk85184451 I read from the comments that you have your Java class in the same folder. This error clearly says that the Java class is not available. In your case it can be because that the Java Class is not compiled properly. If you see that your Java Class name is in small letters. As per Java standards and compiler , you need your Class name to start with Capital case. This will compile your Java classes properly and this issue should get resolved I believe. Please change your Java class name to MyComponent.java and test this

 

Disclaimer:- I am not 100% sure on this since I have never used Java class inside component. but give it a try 😉 and let us know

 

Side note:- I would recommend always writing Sling Models rather than writing it inside the component folder itself. 

 

Veena ✌