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
Solved! Go to Solution.
Views
Replies
Total Likes
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:
However, I still don't see it being set on the page properties:
I feel close, but not quite there yet.
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?
Thanks,
Nikita Garg
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?
Jeremy
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:
However, I still don't see it being set on the page properties:
I feel close, but not quite there yet.
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);
}
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
Views
Likes
Replies