Expand my Community achievements bar.

SOLVED

ModifiableValueMap put checkbox value

Avatar

Level 2

In my .content.xml, I have a property set by a checkbox:

 

<pinterestShareControl
        jcr:primaryType="nt:unstructured"
        sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
        fieldDescription="Controls code for displayihg Pinterest save button."
        name="./showPinterestSave"
        renderReadOnly="{Boolean}true"
        text="Show Pinterest save button on images"
        value="{Boolean}true">
        <granite:data
                jcr:primaryType="nt:unstructured"
                allowBulkEdit="{Boolean}true"
                cq-msm-lockable="showPinterestSave"/>
</pinterestShareControl>

I need to update this property from a servlet I'm writing.  My code is here:

ResourceResolver resourceResolver = null;
resourceResolver = request.getResourceResolver();
Resource myResource = resourceResolver.getResource("/content/my-company/language-masters/en/path/to/the/content");
ModifiableValueMap properties = myResource.adaptTo(ModifiableValueMap.class);
properties.put("showPinterestSave", "True");
resourceResolver.commit();

This finds the resource, but I get the error:

"Value 'true' for property 'showPinterestSave' can't be put into node '/content/my-company/language-masters/en/path/to/the/content'"

 

I have tried sending a 1, true, "True", and "true".  All of these give me the error about the value on the property.  What is the proper way to format the value for this so my checkbox is updated to true?

 

Thanks!

 

Jeremy

1 Accepted Solution

Avatar

Correct answer by
Level 2

Nikita,

Well, I may have made some progress.  I added /jcr:content to the end of the path for my asset and now I'm seeing my property in CRXDE:

 

jeremyc82321732_0-1671728128003.png

 

However, I still don't see it being set on the page properties:

 

jeremyc82321732_2-1671728190572.png

 

I feel close, but not quite there yet.

 

View solution in original post

5 Replies

Avatar

Employee Advisor

hi @jeremyc82321732 ,

 

Your checkbox value is String. and I tried with above code, it works for me.

 

Only doubt I have, while getting resource, are you giving path till component or Page?

 

Resource myResource = resourceResolver.getResource("/content/my-company/language-masters/en/articles/jcr:content/root/container/container/helloworld");
 
Hope this helps

 

Thanks,

Nikita Garg

Avatar

Level 2

Nikita,

 

Interesting!  It works for you but not me

 

The path "/content/trex/language-masters/en/deck-ideas/qa-with-diy-pete" is the path to the page.  If I put the .html on the end, getResource returns null.

 

I also noticed that if I hover over the properties in VS Code, I don't see this property.  Should I?  Is it possible I am somehow not getting the page at all?

 

jeremyc82321732_0-1671726123423.png

 

Jeremy

Avatar

Correct answer by
Level 2

Nikita,

Well, I may have made some progress.  I added /jcr:content to the end of the path for my asset and now I'm seeing my property in CRXDE:

 

jeremyc82321732_0-1671728128003.png

 

However, I still don't see it being set on the page properties:

 

jeremyc82321732_2-1671728190572.png

 

I feel close, but not quite there yet.

 

Avatar

Community Advisor

Try with

 

try {
ResourceResolver resourceResolver = request.getResourceResolver();
Resource myResource = resourceResolver.getResource("/content/my-company/language-masters/en/path/to/the/content/jcr:content");
ModifiableValueMap properties = myResource.adaptTo(ModifiableValueMap.class);
properties.put("showPinterestSave", true);
resourceResolver.commit();
} catch (PersistenceException e) { 
LOGGER.error("Could not save showPinterestSave property", e); 
}

 



Arun Patidar

Avatar

Level 2

Ah, it turns out that "true" and "True" are not equivalent.  I changed to the lower-case one and all is well now.

 

Thanks!

 

Jeremy