Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

PageManager API not creating components

Avatar

Level 2

Using AEM 6.3.

We are generating some recipe detail pages programmatically based on recipe data using the PageManager API.

The recipe detail page is based on a template which contains a collection of components.

When creating a recipe detail through the Touch UI (Sites > Create > Page > Template: Recipe Detail > Name: RecipeTest) the page is created as shown below.

Screen Shot 2018-01-04 at 09.36.28.png

RecipeTest Node Properties

RecipeTest Node.png

jar:content Node Properties

JcrContent Node.png

However, when using the PageManager API as illustrated in the code snippet below, which uses the same template it behaves differently.

// Create Page

PageManager pageManager = resourceResolver.adaptTo(PageManager.class);

prodPage = pageManager.create(path, pageName, _recipeDetailsTemplate, pageTitle, true);

_logger.debug(String.format("Created page using Template[%s]", _recipeDetailsTemplate));

Node pageNode = prodPage.adaptTo(Node.class);

Node jcrNode = null;

if (prodPage.hasContent()) {

     jcrNode = prodPage.getContentResource().adaptTo(Node.class);

     jcrNode.setPrimaryType("cq:PageContent");

     _logger.debug(String.format("hasContent() so adapted Path[%s]", jcrNode.getPath()));

} else {

     jcrNode = pageNode.addNode("jcr:content", "cq:PageContent");

}

jcrNode.setProperty("cq:template", _recipeDetailsTemplate);

jcrNode.setProperty("sling:resourceType", _recipeDetailsRenderer);

_logger.debug(String.format("Set Renderer[%s]", _recipeDetailsRenderer));

_jcrSession.refresh(true);

When using the PageManager as shown above I expected to get the same behaviour but what gets created is this.

Screen Shot 2018-01-04 at 09.26.06.png

You'll notice it is missing the root node and the recipetitle component node.

RecipeTest Node Properties

RecipeTest Node.png

jar:content Node Properties

JcrContent Node.png

I was expecting the page content to be created (recipe title component or whatever is on the specified template) but when creating the page programmatically that doesn't happen.

Clearly I'm missing something, can anyone help?

1 Accepted Solution

Avatar

Correct answer by
Level 10

I got it to work perfectly using the Page Manager API

Page.png

Helpx community article here -- Scott's Digital Community: Creating an Experience Manager 6.3 Page using the Page Manager API

View solution in original post

8 Replies

Avatar

Level 10

Does the page you created with code open?

Avatar

Level 10

I am working on this use case and will post back findings. We will also create a HELPX article that shows use of the PageManager API to create pages.

Avatar

Employee Advisor

Instead of refreshing your session you should save it :-)

Jörg

Avatar

Correct answer by
Level 10

I got it to work perfectly using the Page Manager API

Page.png

Helpx community article here -- Scott's Digital Community: Creating an Experience Manager 6.3 Page using the Page Manager API

Avatar

Administrator

I would recommend, session.save(); first then session.refresh(true) [If needed];

Source:- https://www.albinsblog.com/2014/12/programmatically-create-page-in-cq5.html#.WlNpo0qWbRY



Kautuk Sahni

Avatar

Level 2

Thank you so much for the responses, I've been asked to focus on something else for a short while but I will be returning to this very soon.