Hi
I am unable to invoke bundle class from sightly. I can able to access the same class using scriptlet in jsp.
my code looks similar to this :
<div data-sly-use.mycomp="${ 'com.myproject.MyComponent'}"> ${mycomp.calculatedValue} </div>
Above code is giving error like : use is not able to find
'com.myproject.MyComponent'
when I remove single codes, I am not getting error. but MyComponent class is not invoking. I have extended WCMUse class in MyComponent.
Pls help me to resolve this issue.
Regards,
Krishh
Hi,
Make sure you are exporting your packages
No need to use curly braces
Create a project with archetype 10 and take a look at hello world component..
Here is the example which shows this use case:http://adobeaemclub.com/access-osgi-service-from-the-wcmuse-class-in-sightly/
Hi,
Thanks for the reply :)
Still I am unable to invoke the java class.
PFA code snippets :
<%@page session="false"%><%@ page import="com.day.cq.wcm.foundation.Placeholder" %>
<%
%><%@include file="/libs/foundation/global.jsp"%><%
%>
<div data-sly-use.districtinfo="com.aem.emitra.core.sightly.districtinfo">
${districtinfo.emitraDistricJson}
</div>
package com.aem.emitra.core.sightly;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.cq.sightly.WCMUse;
public class districtinfo extends WCMUse {
//private EmitraDistrictServiceImpl emitraDistrictServiceImpl;
private String emitraDistricJson;
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
public void activate() {
logger.info("inside districtinfo");
//emitraDistricJson=emitraDistrictServiceImpl.getDistrictsJSON();
emitraDistricJson="KRISHH";
}
public String getEmitraDistricJson() {
return emitraDistricJson;
}
}
Java Code:
Views
Replies
Total Likes
Hey,
What is the extension of file in which you have written
<%@page session="false"%><%@ page import="com.day.cq.wcm.foundation.Placeholder" %>
<%
%><%@include file="/libs/foundation/global.jsp"%><%
%>
<div data-sly-use.districtinfo="com.aem.emitra.core.sightly.districtinfo">
${districtinfo.emitraDistricJson}
</div>
You cannot have java code inside sightly file
Views
Replies
Total Likes
edubey wrote...
Hey,
What is the extension of file in which you have written
<%@page session="false"%><%@ page import="com.day.cq.wcm.foundation.Placeholder" %>
<%
%><%@include file="/libs/foundation/global.jsp"%><%
%>
<div data-sly-use.districtinfo="com.aem.emitra.core.sightly.districtinfo">
${districtinfo.emitraDistricJson}
</div>
You cannot have java code inside sightly file
Yeah. I tried with html also like
<div data-sly-use.districtinfo="com.aem.emitra.core.sightly.districtinfo">
${districtinfo.emitraDistricJson}
</div>
its not working. I was thinking about hw sightly will get that path of districtinfo.java . So I have changed again to jsp extension with import statements.
even with the above code I am not able to invoke districtinfo.java.
Views
Replies
Total Likes
Go to localhost:4502/system/console/services and see whether your service is available or not.
Use
<div data-sly-use.districtinfo="com.aem.emitra.core.sightly.districtinfo">
${districtinfo.emitraDistricJson}
</div>
and share the error from error.log
Views
Replies
Total Likes
I have not created any service. My bundle is in http://localhost:4502/system/console/bundles. Do I need to create service? Here I am just displaying hardcoded value. Can you share your gmail id?
Views
Replies
Total Likes
krishh_187 wrote...
I have not created any service. My bundle is in http://localhost:4502/system/console/bundles. Do I need to create service? Here I am just displaying hardcoded value. Can you share your gmail id?
Hey edubey,
I have tried by changing class name as EmitraDistricts. Now it started working. Is there any naming conventions? I have followed component name initially.
Anyways thanks mate. Thanks alot.
Regards
Krishh
Views
Replies
Total Likes
krishh_187 wrote...
Hi,
Thanks for the reply :)
Still I am unable to invoke the java class.
PFA code snippets :
<%@page session="false"%><%@ page import="com.day.cq.wcm.foundation.Placeholder" %>
<%
%><%@include file="/libs/foundation/global.jsp"%><%
%>
<div data-sly-use.districtinfo="com.aem.emitra.core.sightly.districtinfo">
${districtinfo.emitraDistricJson}
</div>
package com.aem.emitra.core.sightly;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.cq.sightly.WCMUse;
public class districtinfo extends WCMUse {
//private EmitraDistrictServiceImpl emitraDistrictServiceImpl;
private String emitraDistricJson;
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
public void activate() {
logger.info("inside districtinfo");
//emitraDistricJson=emitraDistrictServiceImpl.getDistrictsJSON();
emitraDistricJson="KRISHH";
}
public String getEmitraDistricJson() {
return emitraDistricJson;
}
}
Java Code:
Though I have included the import of package also not working
<%
%><%@include file="/libs/foundation/global.jsp"%><%
%>
<%@page session="false"%>
<%@ page import="com.day.cq.wcm.foundation.Placeholder,
com.aem.emitra.core.sightly.districtinfo"
%>
<div data-sly-use.districtinfo="com.aem.emitra.core.sightly.districtinfo">
${districtinfo.emitraDistricJson}
</div>
Views
Replies
Total Likes
I do agree that you have included packages but sightly files have .html extension in which you cannot write java code
So please remove
<%
%><%@include file="/libs/foundation/global.jsp"%><%
%>
<%@page session="false"%>
<%@ page import="com.day.cq.wcm.foundation.Placeholder,
com.aem.emitra.core.sightly.districtinfo"
%>
Views
Replies
Total Likes
krishh_187 - follow this article - you will learn how to use Java and Sightly:
https://helpx.adobe.com/experience-manager/using/creating-sightly-component.html
Views
Replies
Total Likes