Expand my Community achievements bar.

SOLVED

Can I call java from sightly?

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Level 10
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.

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10
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.

Avatar

Level 10

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.