Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
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

4 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 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