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
@component(
service = SlingPostProcessor.class,
immediate = true,
property = {
"service.ranking:Integer=-1"
},
configurationPolicy = ConfigurationPolicy.REQUIRE
)
public class ComponentAPostProcessor implements SlingPostProcessor {
@Override
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.
@component(
service = SlingPostProcessor.class,
immediate = true,
property = {
"service.ranking:Integer=-1"
},
configurationPolicy = ConfigurationPolicy.REQUIRE
)
public class ComponentBPostProcessor implements SlingPostProcessor {
@Override
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 ?
Views
Replies
Total Likes
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.
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()));
}
}
@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?
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 ?
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
@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.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies