Sling Model Multivalue Page level property reading | Community
Skip to main content
khamat_bn
Level 4
Jun 8, 2020 9:43 PM UTC
Solved

Sling Model Multivalue Page level property reading

Hello Guys,

I want to read the property of page level cq:tags which will be multivalue. If I trying to read the property by 

pageNodes.getProperty("cq:tags").getValue().toString()

its saying cq:tags is multivalue. can anyone tell me how i can read this property.

 

Regards,

~BK

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
khamat_bn
khamat_bnAccepted solution
Level 4
Jun 9, 2020 8:04 AM UTC

Hello @a74048191r ,

Thanks for the response, I tried the lines that u posted. Unfortunately, it didn't work for me.

But I ended up with the solution that works for me. Posting Here so others can also use it if required.

private Value[] tagsFromPage;

for
(Value eachTag : tagsFromPage) {
log.info("tagsFromPage value: {}", eachTag.toString());
}

 

3 replies

khamat_bn
khamat_bnAuthorAccepted solution
Level 4
Jun 9, 2020 8:04 AM UTC

Hello @a74048191r ,

Thanks for the response, I tried the lines that u posted. Unfortunately, it didn't work for me.

But I ended up with the solution that works for me. Posting Here so others can also use it if required.

private Value[] tagsFromPage;

for
(Value eachTag : tagsFromPage) {
log.info("tagsFromPage value: {}", eachTag.toString());
}

 

Translate
Level 3
Jul 4, 2023 5:09 AM UTC

@khamat_bn Can you please add the code on how you are storing the cq:tags values into the tagsFromPage array?

Translate
Level 2
Jun 8, 2020 10:10 PM UTC

try this:

Value[] values = pageNodes.getProperty("cq:tags").getValues();
 
then iterate as needed

                for (Value value : values) {
                    Tag tag = tagManager.resolve(value.getString());
                }
Translate