Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Java: how to best update the jcr:contents of a page?

Avatar

Level 8

So I have an Excel spreadsheet processor/importer where all existing pages are deleted and then it recreates the pages based on the spreadsheet info.

I'm creating new pages via

Page page = pageManager.create(getCorrectPath(main, fish), getValidName(fish), templatePath, fish.getName(), true);

and this creates new pages under /content/data/fishes.

There is a new need where I cannot delete the pages anymore. I need to update it in possibility it's an existing one.

example:

/content/data/fishes/greatwhale

jcr:contents

  species:arachnid

on the spreadsheet, the species has been updated to fish.

I've looked at com.day.cq.wcm.api.PageManager  and com.day.cq.wcm.api.Page

Reading these 2 pages, it seems to me there is no update/edit facility available. So I'm thinking the next option is to delete the page and then recreate it?

Or perhaps you have a better suggestion?

Thank you so much!

1 Accepted Solution

Avatar

Correct answer by
Level 10

You should use ModifiableValueMap

https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ModifiableValueMap.html

Sample code

ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class);

properties.put("key", "value");

resourceResolver.commit();

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

You should use ModifiableValueMap

https://sling.apache.org/apidocs/sling7/org/apache/sling/api/resource/ModifiableValueMap.html

Sample code

ModifiableValueMap properties = resource.adaptTo(ModifiableValueMap.class);

properties.put("key", "value");

resourceResolver.commit();

Avatar

Level 10

With PageManager API - you can create new pages - we have a new article that shows this -- Scott's Digital Community: Creating an Experience Manager 6.3 Page using the Page Manager API (be released week of Jan 8)