Hello Team,
Wanted to check the actual use case of Optional.Nullable in AEM section.
Why Part 1 is preferred over Part 2? Is it because of developer-friendly code?
I have observed that in Part 1, by mistake if I add jcr:content at the end, i mean:
String currentPagePath = "/content/abc/us/en/jcr:content"; then application throws error.
Part 1:
String currentPagePath = "/content/abc/us/en";
Resource resource = resourceResolver.getResource(currentPagePath);
String templateName= Optional.ofNullable(resource.adaptTo(Page.class).getTemplate().getPath()).orElse("");
String pageTitle= Optional.ofNullable(resource.adaptTo(Page.class).getTitle()).orElse("");
Part 2:
String resourcePath = "/content/abc/us/en";
resource=resourceResolver.getResource(resourcePath+"/jcr:content");
if(resource !=null) {
ValueMap properties = resource.getValueMap();
String pageTitle = properties.get("jcr:title", String.class);
}