Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Unable to invoke bundle class using sightly

Avatar

Level 4

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

10 Replies

Avatar

Level 10

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-ser­vice-from-the-wcmuse-class-in-sightly/

Avatar

Level 4

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:

Avatar

Level 10

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

Avatar

Level 4

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.

Avatar

Level 10

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

Avatar

Level 4

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?

Avatar

Level 4

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

Avatar

Level 4

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>

Avatar

Level 10

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"
%>