Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Load a WCMUsePojo class inside of a JSP template

Avatar

Level 1

Hi,

 

I'm currently rewriting a Sightly template as JSP (I usually prefer using Sightly, but I need JSP for this use case).

 

In our Sightly template, we are loading in a model class that inherits from WCMUsePojo:

 

<sly data-sly-use.search="edu.nyu.aemnyu.core.components.content.news.Search" data-sly-unwrap>

When I try mimicking this in the JSP template:

 

Search search = resource.adaptTo(Search.class);

The "activate()" method doesn't seem to get invoked, which tells me I'm doing something wrong.

 

Am I missing a better way to handle this in JSP? I'm hoping to avoid re-writing the Search class referenced above  since its used elsewhere.

 

Thank you in advance,

Scott

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

WcmUsePojo is a bit restricted in its usability, and for that reason the Sling Models have been implemented. You might want to convert pojo to a Sling Model, in most cases it's straight forward.

View solution in original post

5 Replies

Avatar

Community Advisor

Hi @scottfinkelstein 
I am not sure if you can use WCMUsePojo in the JSP but you can use sling model in JSP
https://sling.apache.org/documentation/bundles/models.html#client-code-1 



Arun Patidar

Avatar

Correct answer by
Employee Advisor

WcmUsePojo is a bit restricted in its usability, and for that reason the Sling Models have been implemented. You might want to convert pojo to a Sling Model, in most cases it's straight forward.

Avatar

Level 1

Thank you both! I converted the WCMUsePojo class to a Sling Model, and that worked within my JSP file. It also worked well in that I was able to use it in our Sightly template, thereby retiring the WCMUsePojo class.

 

Thanks again!

Scott

Avatar

Administrator

@scottfinkelstein 

I trust you found the AEM community useful. We look forward to seeing you return as either a learner or a contributor. The community is enriched by SMEs like you. Encourage your AEM peers to contribute here as well. Happy AEM learning!

 


Kautuk Sahni

Avatar

Administrator

@scottfinkelstein Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni