This is my sightly code :
<sly data-sly-use.search="amitsample.core.Services.Develope">
${search.details}
</p>
this is my bundle which I uploaded in felix console :
This is my path where i set my maven project:
Develope.java
================
And these are my code:
package amitsample.core.filters;
import com.adobe.cq.sightly.WCMUse;
import amitsample.core.filters.HelloService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Develope extends WCMUse {
Logger logger = LoggerFactory.getLogger(Develope.class);
protected String detail;
@Override
public void activate() throws Exception {
/*HelloService serv= getSlingScriptHelper().getService(HelloService.class);
detail=serv.getRepositoryName();
logger.info("this is the first log values");*/
logger.info("this is the first log values");
}
public String getDetails() {
return "Amitgggg";
}
}
HelloService.java
=============
package amitsample.core.filters;
/**
* A simple service interface
*/
public interface HelloService {
/**
* @return the name of the underlying JCR repository implementation
*/
public String getRepositoryName();
}
HelloServiceImpl.java
===================
package amitsample.core.filters;
import javax.jcr.Repository;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.jcr.api.SlingRepository;
@Service
@Component(metatype = false)
public class HelloServiceImpl implements HelloService {
@Reference
private SlingRepository repository;
public String getRepositoryName() {
return repository.getDescriptor(Repository.REP_NAME_DESC);
}
}
Now I am setting logs to see whether it is working or not but I am not getting anything in my logs and in which page I am dragging and dropping the component that uses develop.java (WCMuse class) file thru sightly, There also no value I am expecting return "Amitgggg"; this in my page but not getting any idea what is the problem .
Solved! Go to Solution.
Hi,
try below
<p data-sly-use.search="amitsample.core.filters.Develope">
${search.details}
</p>
You can directly call services in HTL like above
<p data-sly-use.servObj="amitsample.core.filters.HelloService">
${servObj.repositoryName}
</p>
Hi,
try below
<p data-sly-use.search="amitsample.core.filters.Develope">
${search.details}
</p>
You can directly call services in HTL like above
<p data-sly-use.servObj="amitsample.core.filters.HelloService">
${servObj.repositoryName}
</p>
silly mistake ...Arun Thnaks a lot ...I was hitting my brain on this for so long ..Really helpful.....
Views
Replies
Total Likes
One doubt :
here ${search.details}
details is what?
It came from method
public String getDetails form this part?
Similarly
${servObj.repositoryName}?
It came from method
public String getRepositoryName()?
Views
Replies
Total Likes
Hi,
Yes, you need to name method in java with getMethodName and HTL you use methodName to invoke same method.
<p data-sly-use.search="amitsample.core.filters.Develope">
${search.details}
</p>
above one is working fine and I am getting result on my page where i dragged the component .
Now i tried the second option:
You can directly call services in HTL like above
<p data-sly-use.servObj="amitsample.core.filters.HelloService">
${servObj.repositoryName}
</p>
this is not working ..I have not changed any code as pasted in above in my question just using services directly in Sightly as you suggested but I am getting error like below:
org.apache.sling.scripting.sightly.SightlyException: Identifier amitsample.core.filters.HelloService cannot be correctly instantiated by the Use API
Page | = | /content/srevice | |
Resource Path | = | /content/srevice/jcr:content/par12/servicecompo | |
Cell | = | servicecompo | |
Cell Search Path | = | pagerendring|page/par12|parsys/servicecompo | |
Component Path | = | /apps/amitsample/components/content/servicecompo |
Any Idea?
Views
Replies
Total Likes
Hi,
Could be issue with your service implementation.
I tried below code, working fine -
package com.aem.community.core.forum;
import javax.jcr.Repository;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@Component(service = HelloService.class, immediate = true)
public class HelloServiceImpl implements HelloService {
@Reference
private SlingRepository repository;
public String getRepositoryName() {
return repository.getDescriptor(Repository.REP_NAME_DESC);
}
}
Hi Arun,
You have not used @Service annotation so does it mean that is not service ?It is a component.
Views
Replies
Total Likes
Hi,
I used osgi annotation, in osgi annotations service are created like above. more info at below:
Using OSGi annotations (>= AEM6.2) - Experience Delivers
Views
Replies
Total Likes
Hello,
I am trying to consume a method in OSGi service to read its OSGi config value, from a simple HTL tag. But I always see that the "<service class> cannot be resolved to a type" error always, though my OSGI bundle is up and the service is shown to be REGISTERED and active. Any pointers on why am I facing the same issue while using like <p data-sly-use=fully_qualified_servicename>
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies