Hi All,
In an AEM 6.3 project , how can I get the current Page reference from a Java 'Model' class , for example 'HelloWorldModel' (see example source below).
I would like to pass reference to current Page to Navigation (com.day.cq.wcm.foundation.Navigation).
On AEM 6.1 there was method getCurrentPage() defined in com.adobe.cq.sightly.WCMUsePojo which was the parent class for a Component bean class.
On AEM 6.3 I don't have access to getCurrentPage() from the 'Model' class (see example below).
Thanks,
Robert
----
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Default;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.settings.SlingSettingsService;
@Model(adaptables=Resource.class)
public class HelloWorldModel {
@Inject
private SlingSettingsService settings;
@Inject @Named("sling:resourceType") @Default(values="No resourceType")
protected String resourceType;
private String message;
@PostConstruct
protected void init() {
message = "\tHello World!\n";
message += "\tThis is instance: " + settings.getSlingId() + "\n";
message += "\tResource type is: " + resourceType + "\n";
}
public String getMessage() {
return message;
}
}
Solved! Go to Solution.
Views
Replies
Total Likes
2 changes you need to make:
1. make your class adaptable from SlingHttpServletRequest
2 add the following
@Inject
private Page currentPage;
2 changes you need to make:
1. make your class adaptable from SlingHttpServletRequest
2 add the following
@Inject
private Page currentPage;
Feike Visser - any examples of this in GitHub?
Views
Replies
Total Likes
Check this from the core-components: aem-core-wcm-components/PageImpl.java at master · Adobe-Marketing-Cloud/aem-core-wcm-components · Gi...
Link is showing as 404 error..
Views
Likes
Replies
Views
Likes
Replies