Resolving Sling Model in Jsp files
Hi All,
I like to know if there is a way that jsp files can interpret Sightly just like html files. Let’s use the AEM demo HelloWorldModel
In my jsp file, this will work
<%@include file="/apps/mysite/components/global.jsp" %>
<%@page session="false" import=“mysite.core.models.HelloWorldModel"%>
<c:set var=“helloModel” value="<%= resource.adaptTo(HelloWorldModel.class)%>"/>
<div>Message : ${helloModel.message}</div> <!-- will see the message -->
In the helloworld component from AEM, which has a “.html” default extension, it also works
<p data-sly-test="${properties.text}">Text property: ${properties.text}</p>
<pre data-sly-use.hello="mysite.core.models.HelloWorldModel">
HelloWorldModel says:
${hello.message} <!-- will see the message -->
</pre>
But when I include the the helloworld model in the jsp file, it doesn’t work. I include it in one of my page template “.jsp” file,
<pre data-sly-use.hello="mysite.core.models.HelloWorldModel">
HelloWorldModel says:
${hello.message} <!-- can’t see the message -->
</pre>
It can’t interpret the sling model because jsp doesn’t understand the Sightly syntax. We have tons of jsp files, most of them use a lot of beans, which are equally the same as sling models. We may not be able to convert all the beans into sling models in phase one, so we may need to mix them together.
Thanks!
-kt