Esta conversación ha sido bloqueada debido a la inactividad. Cree una nueva publicación.
Nivel 1
Nivel 2
Iniciar sesión en la comunidad
Iniciar sesión para ver todas las insignias
Esta conversación ha sido bloqueada debido a la inactividad. Cree una nueva publicación.
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
¡Resuelto! Ir a solución.
Vistas
Respuestas
Total de me gusta
Hi @kevingtan,
You cannot include sightly tags in a jsp, however you can include a jsp component in sightly, for example
<sly data-sly-resource="${'par1' @ resourceType='projectname/components/content/foldername/componentname'}"/>
where projectname/components/content/foldername/componentname points to a JSP component.
In your case, I would suggest component by component migration to sightly and Sling Modals i.e if you're migrating 1 component, then change to both sightly and Sling Modal at the same time. You can still have mix of components with some written in jsp and some in sightly and Sling Modals.
You can also go through this tool for modernising your components - https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/migration-journey/r...
Thanks,
Chitra
Vistas
Respuestas
Total de me gusta
Hi @kevingtan,
You cannot include sightly tags in a jsp, however you can include a jsp component in sightly, for example
<sly data-sly-resource="${'par1' @ resourceType='projectname/components/content/foldername/componentname'}"/>
where projectname/components/content/foldername/componentname points to a JSP component.
In your case, I would suggest component by component migration to sightly and Sling Modals i.e if you're migrating 1 component, then change to both sightly and Sling Modal at the same time. You can still have mix of components with some written in jsp and some in sightly and Sling Modals.
You can also go through this tool for modernising your components - https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/migration-journey/r...
Thanks,
Chitra
Vistas
Respuestas
Total de me gusta
Thanks for your detailed suggestion. I will try that out.
Vistas
Respuestas
Total de me gusta
It will not work if you use sightly tag in JSP.
I am not sure why are you using sling model in jsp, but I think you can call it thru adaptTo method.
Inside jsp's scriptlet you get the global object request or resource(it depends) adapt the sling model from it like:
HelloWorldModel helloWorldModel = resource.adaptTo(HelloWorldModel.class);
in the above snippet, Sling model was adaptables to Resource so I adapted it from resource but this depend on our use case.
Please see below link
https://aemhelper.blogspot.com/2021/08/common-myths-around-sling-model.html
Hope this helps
Umesh Thakur
Vistas
Respuestas
Total de me gusta
Hi @Umesh_Thakur ,
We have a lot of beans for page templates, not only components. For instance, event landing page template has a bean class associated with the front-end jsp file via a bean resolver, and there are a lot of jsp and jstl in the file. Some page templates are quite complicated such as including other static components as drawers, breadcrumb, CTA, etc. I am trying to convert the bean to sling model, while reviving the jsp slowly. That's my purpose using sling model in jsp, I may have to wipe out the whole jsp file if that's not the way to go.
Vistas
Respuestas
Total de me gusta
@kevingtan if you want to be funky, you can reference a sightly HTL script, <%@include file="/apps/mysite/components/myhtml.html" %>, and from there, the myhtml.html should be referencing a sling model. That should work.
Vistas
Respuestas
Total de me gusta
Thanks for the suggestion. I will try that out.
Vistas
Respuestas
Total de me gusta
The Sling Model documentation points out a few ways to include a sling model: https://sling.apache.org/documentation/bundles/models.html#client-code-1, and both the scriptlet way and the <sling:adaptTo> tag should work in the context of a JSP.
Vistas
Respuestas
Total de me gusta
Vistas
me gusta
Respuestas
Vistas
me gusta
Respuestas
Vistas
me gusta
Respuestas