Hi all,
I have a legacy component written in jsp. Can i have sample on how to read an OSGI configuration property inside the jsp. I already have the OSGI configuration service , how can i use it within the component.jsp to set some data attribute to a div for the values configured inside osgi config.
Solved! Go to Solution.
Views
Replies
Total Likes
@TrentDeb JSP in AEM in 2024 ? Surprised to see that. Please move to sightly ASAP if possible
For JSP
Please check this SlingScriptHelper defined objects to access the service.
https://sling.apache.org/documentation/bundles/scripting/scripting-jsp.html#defineobjects
https://sling.apache.org/apidocs/sling9/org/apache/sling/api/scripting/SlingScriptHelper.html
<%@include file="/libs/foundation/global.jsp"%>
<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %>
<sling:defineObjects />
@TrentDeb JSP in AEM in 2024 ? Surprised to see that. Please move to sightly ASAP if possible
For JSP
Please check this SlingScriptHelper defined objects to access the service.
https://sling.apache.org/documentation/bundles/scripting/scripting-jsp.html#defineobjects
https://sling.apache.org/apidocs/sling9/org/apache/sling/api/scripting/SlingScriptHelper.html
<%@include file="/libs/foundation/global.jsp"%>
<%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %>
<sling:defineObjects />
Hi @TrentDeb
Good suggestion by @Saravanan_Dharmaraj , Please put suggestion to leads to move to Sightly.
By the way here is the solution you can try this way:
<%@include file="/libs/foundation/global.jsp"%>
<%@page import="org.apache.sling.api.scripting.SlingScriptHelper"%>
<%@page import="com.example.aem.config.MyConfigService"%>
<%
// Get the SlingScriptHelper
SlingScriptHelper sling = slingRequest.getSlingScriptHelper();
// Get your OSGi service
MyConfigService configService = sling.getService(MyConfigService.class);
// Get the configuration value
String myValue = configService.getMyValue();
%>
<div data-my-value="<%= myValue %>">...</div>
Hope this will help!
Views
Likes
Replies
Views
Likes
Replies