I am using AEM6.1. is there any way to call our own java classes and methods from sightly without following the below approach:
<div data-sly-use.info="Info">
<h1>${info.lowerCaseTitle}</h1>
<p>${info.lowerCaseDescription}</p>
</div>
package apps.my_example.components.info;
import com.adobe.cq.sightly.WCMUse;
public class Info extends WCMUse {
.......................
.......................
}
Can't I call my own custom java classes without importing ( import com.adobe.cq.sightly.WCMUse; ). Is there any method or other approach available in sightly.
Thank you,
Arnab
Solved! Go to Solution.
Views
Replies
Total Likes
Adding to what @scott mentioned, use this piece of code for calling service, referenceSimple.java public class Simple extends WCMUse { private String myTitle; @Override public void activate() { myTitle = "AEM " + getCurrentPage().getTitle(); MyService service = getSlingScriptHelper().getService(MyService.class); service.action(myTitle); } public String getMyTitle() { return myTitle; } }
Share your use case it this isn't clear to you.
Views
Replies
Total Likes
Adding to what @scott mentioned, use this piece of code for calling service, referenceSimple.java public class Simple extends WCMUse { private String myTitle; @Override public void activate() { myTitle = "AEM " + getCurrentPage().getTitle(); MyService service = getSlingScriptHelper().getService(MyService.class); service.action(myTitle); } public String getMyTitle() { return myTitle; } }
Share your use case it this isn't clear to you.
Views
Replies
Total Likes
You do not call Java like you do in JSP:
custom.querybuilder.SearchService queryBuilder = sling.getService(custom.querybuilder.SearchService.class);
You call Java as specified in this article:
https://helpx.adobe.com/experience-manager/using/creating-sightly-component.html
If you want to call a Java service using sling.getService - use JSP - not Sightly.
Views
Replies
Total Likes