Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

Use cases of ModifiableValueMap in AEM | AEM Community Blog Seeding

kautuk_sahni
Community Manager
Community Manager

BlogImage.jpg

Use cases of ModifiableValueMap in AEM by aem-ti2fap blogspot

Abstract

The ModifiableValueMap is an extension of the ValueMap which allows to modify and persist properties.
All changes to this map are stored in the transient layer of the resource resolver or more precisely in the transient layer of the resource provider managing this resource.
Use cases in AEM ::

Mandatory step -
1. Get the resource resolver.
2. Get ModifiableValueMap interface -
ModifiableValueMap mvp = resolver.adaptTo(ModifiableValueMap.class);

1. Get SINGLE value property of a node:
String value = mvp.get("multivalue", String.class);

2. Get MULTI value property of a node:
String[] value = mvp.get("multivalue", String[].class);

3. Add SINGLE value property to a node:
String val = "single";
a. mvp.put("singlevalue", val);
b. mvp.putIfAbsent("singlevalue", val);


4. Add MULTI value property to a node:
String[] val = {"test1","test2"};
mvp.put("multivalue", val);

5. Add MULTIPLE properties to a node:
Map<String, String[]> map = new HashMap<>();
map.put("prop1", val1);
map.put("prop2", val2);
mvp.putAll(mapp);

P.S.- Perform resolver.commit() after put operation and do resolver.close() after completing all resource resolver related operations.

Read Full Blog

Use cases of ModifiableValueMap in AEM

Q&A

Please use this thread to ask the related questions.

0 Replies