Load a WCMUsePojo class inside of a JSP template | Community
Skip to main content
December 15, 2023
Solved

Load a WCMUsePojo class inside of a JSP template

  • December 15, 2023
  • 3 replies
  • 1174 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

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.

3 replies

arunpatidar
Community Advisor
Community Advisor
December 18, 2023

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
joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
December 22, 2023

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.

December 22, 2023

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

kautuk_sahni
Community Manager
Community Manager
June 7, 2024

@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
kautuk_sahni
Community Manager
Community Manager
January 2, 2024

@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