- Then I have to invoke a Servlet on every page and with the use of the selector want to return some information in JSON format which can be used to display via Component on a Page to end-user.
- Then with the use of a particular selector, we can get results like list information/required custom information for every AEM page and display either via component with its ajax request has a url of Current Page. Selector which invokes the Servlet and renders result.
Code Snippet:
@Component(name = "Site-Results", metatype = false, configurationFactory = false, policy = ConfigurationPolicy.OPTIONAL)
@Service(Servlet.class)
@Properties([
@Property(name = "sling.servlet.resourceTypes", value = ["cq/Page"]),
@Property(name = "sling.servlet.selectors", value = "results"),
@Property(name = "sling.servlet.extensions", value = ["json"]),
@Property(name = "sling.servlet.methods", value = "GET"),
@Property(name = "sling.servlet.description", value = "Gives Results for Every Page")
])
class ResultsServlet extends SlingSafeMethodsServlet {
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {
//Implement Your Logic
}
}
No comments:
Post a Comment
If you have any doubts or questions, please let us know.