Hi All,
I am new to cq and i tried example given in adobe forum "By using Sling API,getting the information of page node information from JCR".But i am trying to get the reference of that component into JSP ,null reference is returning.Below are the code snippets.
Interface:
package com.slingapp;
public interface Query
{
public String getJCRData(String location) ;
}
Implemented Class:
package com.slingapp;
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.api.resource.LoginException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Deactivate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.wcm.api.Page;
@Component(immediate=true)
@Service
public class QueryImp implements Query {
//Inject a Sling ResourceResolverFactory
private static final Logger logger = LoggerFactory
.getLogger(QueryImp.class);
@Reference
private ResourceResolverFactory resolverFactory;
String title=null;
public String getJCRData(String location) {
try {
ResourceResolver resResolver = resolverFactory.getAdministrativeResourceResolver(null);
Resource resource=resResolver.getResource("/content/geometrixx/en/services");
Page page=resource.adaptTo(Page.class);
title=page.getTitle();
} catch (LoginException e) {
}
return title;
}
@Activate
protected void activate() {
logger.info("service activated" );
}
@Deactivate
protected void deactivate() {
logger.info ("service deactivated");
}
}
Component Page
<html>
<%@include file="/libs/foundation/global.jsp"%>
//<%@page import="com.slingapp.Query,com.slingapp.QueryImp"%>
<%@taglib prefix="cq" uri="http://www.day.com/taglibs/cq/1.0" %>
<h1>TemplateSling Page</h1>
<%
com.slingapp.Query wfService = sling.getService(com.slingapp.Query.class);
//I have tried as com.slingapp.Query wfService = sling.getService(com.slingapp.QueryImp.class); but no luck
%>
<%=wfService.hashCode()%>
</html>
Can some help me in fixing this issue
Thanks,
Kishore
Solved! Go to Solution.
Views
Replies
Total Likes
See the community article that will walk your through building a CQ bundle that uses the Sling API and then calling the bundle from a JSP:
http://scottsdigitalcommunity.blogspot.ca/2013/09/using-sling-to-retrieve-content-from.html
Hope this helps
Views
Replies
Total Likes
See the community article that will walk your through building a CQ bundle that uses the Sling API and then calling the bundle from a JSP:
http://scottsdigitalcommunity.blogspot.ca/2013/09/using-sling-to-retrieve-content-from.html
Hope this helps
Views
Replies
Total Likes
Hi,
i have followed the same article. Eventhough bundle is active,but still i am not able to get the instance of it.
Thanks,
Kishore.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies