SlingPostProcessor is not invoked after dialog submission in AEM | Community
Skip to main content
Mario248
Level 7
October 3, 2023

SlingPostProcessor is not invoked after dialog submission in AEM

  • October 3, 2023
  • 4 replies
  • 1535 views

I am doing some post-processor work after dialog submission so I am creating a SlingPostProcessor to update the node desired property. SlingPostProcessor  is working for component A but the same is not working for component B


Here is my working component A code. Below process method is invoked as soon I submit the component dialog A

 

 

@8220494( service = SlingPostProcessor.class, immediate = true, property = { "service.ranking:Integer=-1" }, configurationPolicy = ConfigurationPolicy.REQUIRE ) public class ComponentAPostProcessor implements SlingPostProcessor { @9944223 public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception { if ("/component/.....componentA".equals(request.getResource().getResourceType());) { ..... } }

 

 

Here is my not working code(component B). This below process is not invoked after dialog submission. I tried to change the service.ranking:Integer value to 0 and -2 but it is not working. 

 

 

@8220494( service = SlingPostProcessor.class, immediate = true, property = { "service.ranking:Integer=-1" }, configurationPolicy = ConfigurationPolicy.REQUIRE ) public class ComponentBPostProcessor implements SlingPostProcessor { @9944223 public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception { if ("/component/.....componentB".equals(request.getResource().getResourceType());) { ..... } } }

 

 

No error on log. I think service.ranking:Integer=-1 tells which is lower priority but it is not working when I keep the value in two SlingPostProcessor classes. any reason ?

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

4 replies

arunpatidar
Community Advisor
Community Advisor
October 3, 2023

Are you using any return statement inside if?

 

What is a Sling Post Processor?

The SlingPostProcessor interface defines a service API to be implemented by service providers extending the Sling default POST servlet. Service providers may register OSGi services of this type to be used by the Sling default POST servlet to handle specific operations.

During a request the SlingPostOperation service is called with a list of registered post processors. After the operation has performed its changes but before the changes are persistent, all post processors are called.

To be more specific of its working, the SlingPostServlet service collects all available PostProcessor implementations. When a POST call occurs, each of the post processors can modify the metadata for doing something after the POST.

Arun Patidar
Mario248
Mario248Author
Level 7
October 4, 2023

No, I am not returning anything. sample code. aftercompleting business logic I am just adding it list as below.

public void process(SlingHttpServletRequest request, List<Modification> modifications) throws Exception {
final
Resource resource = request.getResource().getChild("accordionList");
final ModifiableValueMap compMvm = request.getResource().adaptTo(ModifiableValueMap.class);
final ModifiableValueMap filtersMvm = Optional.ofNullable(resource).map(res -> res.adaptTo(ModifiableValueMap.class)).orElse(null);

if (compMvm != null && filtersMvm != null) {
compMvm.put("prop1", "propvalue");
modifications.add(Modification.onModified(resource.getPath()));
}
}

 

Shashi_Mulugu
Community Advisor
Community Advisor
October 3, 2023

@mario248 technically you don't need two separate post-processing services,  can you add if else or switch stmts in first postprocessor itself for handing both resource types?

Mario248
Mario248Author
Level 7
October 4, 2023

Yes, technically we can use one SlingPostProcessor instead of two separate post-processing services. However, it should also be possible to use multiple SlingPostProcessors.

 

I would like to separate the component business logic into different SlingPostProcessors, rather than keeping it all in one. Is there any way make it work ? or Should there be only one SlingPostProcessor present ?

Dipti_Chauhan
Community Advisor
Community Advisor
October 4, 2023

Hi

 Why you need to create two slingpostProcessor.it is not tied to one particular resource type.As @shashi_mulugu mentioned you can just have two conditions in same processor. 

Thanks

Dipti

kautuk_sahni
Community Manager
Community Manager
October 4, 2023

@mario248 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