ModifiableValueMap put checkbox value | Community
Skip to main content
jeremyc82321732
December 21, 2022
Solved

ModifiableValueMap put checkbox value

  • December 21, 2022
  • 2 replies
  • 1423 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by jeremyc82321732

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.

 

2 replies

Adobe Employee
December 22, 2022

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

jeremyc82321732
jeremyc82321732AuthorAccepted solution
December 22, 2022

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.

 

arunpatidar
Community Advisor
Community Advisor
December 22, 2022

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
jeremyc82321732
December 22, 2022

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