Expand my Community achievements bar.

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

how to use EventHandler

Avatar

Level 1

1569467_pastedImage_1.png

I  need those  not  null;

what should i do?

thanks.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

You are mixing osgi and Felix annotation.

Please use only osgi annotaions

remove org.apache.felix.scr.annotations.Reference and use import org.osgi.service.component.annotations.Reference;



Arun Patidar

View solution in original post

14 Replies

Avatar

Community Advisor

Hi,

What are you trying to do,

you can get resource resolver from subservice user.

and then get appropriate objects value not null.

@Reference

  private ResourceResolverFactory resourceResolverFactory;

ResourceResolver resourceResolver = null;

  try {

        Map<String, Object> serviceParams = new HashMap<String, Object>();

    serviceParams.put(ResourceResolverFactory.SUBSERVICE, "training");

    resourceResolver = resourceResolverFactory.getServiceResourceResolver(serviceParams);

  } catch (LoginException e) {

  e.printStackTrace();

  }



Arun Patidar

Avatar

Level 1

1569469_pastedImage_0.png

i  don't know  because of  this  ”EventHandler“ 

all I received both of them are null

Avatar

Community Advisor

Can you share your imports?



Arun Patidar

Avatar

Employee Advisor

Have you used the Maven Archetype to boostrap your AEM project?

Jörg

Avatar

Level 1

1569476_pastedImage_0.png

yes  
because i use these Servlet can receive resolverFactory

Avatar

Correct answer by
Community Advisor

Hi,

You are mixing osgi and Felix annotation.

Please use only osgi annotaions

remove org.apache.felix.scr.annotations.Reference and use import org.osgi.service.component.annotations.Reference;



Arun Patidar

Avatar

Level 1

i have to use this EventListener
but  i  need  listener many  pages publish
so i dont know  how to use this

Avatar

Level 10

See the artilce i just posted. Go through it and make it work. I will update this too include a video so you can see it working.