Tried building a dynamic navigation menu with a Sling Model that maps to the navigation data in AEM. In this, I tried to create a NavigationModel class that retrieves the current page and its siblings, and builds a list of NavigationItem objects that represent each page in the navigation menu.
So when I used @PostConstruct annotation to initialize the items list it is giving error as "method buildNavigation(Page) is undefined for the type NavigationModel" & "context cannot be resolved" and also while creating buildNavigation method which uses list of array for child pages giving "The type List is not generic; it cannot be parameterized with arguments" error.In the NavigationItem class showing error in the properties of navigation menu. The error it is throwing "methods undefined for the type Page". Attached the error screenshots for reference.
Solved! Go to Solution.
Views
Replies
Total Likes
Hello @Kiruthiga_Rajendran ,
To get the current page you can simply use this code.
@Model(adaptables = SlingHttpServletRequest.class)
public class MyModel {
@ScriptVariable
private Page currentPage;
@PostConstruct
protected void init() {
// Your code using currentPage
}
}
The code you shared where "context cannot be resolved", the context object you didn't declare.
Hello @Kiruthiga_Rajendran ,
To get the current page you can simply use this code.
@Model(adaptables = SlingHttpServletRequest.class)
public class MyModel {
@ScriptVariable
private Page currentPage;
@PostConstruct
protected void init() {
// Your code using currentPage
}
}
The code you shared where "context cannot be resolved", the context object you didn't declare.
1. you will have to make your class adaptable to SlingHttpServletRequest
and add the following-
A simpler way would be-
@Inject
private Page currentPage;
2. If its Resource.class you could try using the resourceresolver-
@SlingObject
private ResourceResolver resourceResolver;
@SlingObject
private Resource currentResource;PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
pageManager.getPage(currentResource.getPath())
Hello All,
Got cleared with the previously posted query related to Java code. Now I got the new error while rendering custom navigation component in pages. Attaching the error screenshots.
Views
Replies
Total Likes
Views
Likes
Replies