Expand my Community achievements bar.

Adobe Summit 2025: AEM Session Recordings Are Live! Missed a session or want to revisit your favorites? Watch the latest recordings now.

granite/ui/components/coral/foundation/form/checkbox uncheckedValue not working

Avatar

Level 4

Hi Team

 

I have an issue when checkbox is unchecked the value is empty "" instead I would like to store it as false. 
When it is checked I am getting as "true"

 

could you please advise me on the below 2 issues:

1. When checkbox is not checked or unchecked I want value as false

2. When checkbox is checked, i am getting "true" in json which is a string. Can I get as boolean like true.

 

below is my node structure :

<disable
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
fieldDescription="Checking will add a check icon"
name="./disable"
text="disable"
checked="{Boolean}false"
value="{Boolean}true"
deleteHint="{Boolean}false"/>

5 Replies

Avatar

Community Advisor

Hi @Prashardan 

Can you try with new page? it may not work with existing authored component.

Arun Patidar

AEM LinksLinkedIn

Avatar

Level 4

I am using this in the content fragment model. Checked value is coming as true which is fine but unCheckedValue is not coming as false

Avatar

Community Advisor

Avatar

Level 4

@DPrakashRaj I have tried the same way but it is not working. I am using this in the content fragment model. Checked value is coming as true which is fine but unCheckedValue is not coming as false

Avatar

Community Advisor

Hi @Prashardan,

1. When checkbox is unchecked, store value as false

By default, unchecked checkboxes don't submit any value — which is why you’re seeing "" (empty string) or nothing in the JCR node.

Try this:

<disable
    jcr:primaryType="nt:unstructured"
    sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
    fieldDescription="Checking will add a check icon"
    name="./disable"
    text="disable"
    checked="{Boolean}false"
    uncheckedValue="{Boolean}false"
    value="{Boolean}true"
    deleteHint="{Boolean}true"/>

Key changes:

  • uncheckedValue: This ensures false is stored when the checkbox is not checked.

  • deleteHint=true: Ensures the field gets deleted or replaced with the uncheckedValue during POST.

2. Getting "true" as string, want actual boolean true

When reading the value in your servlet/model or exporting it to JSON via Sling Model, sometimes "true" appears as a string because of how it's stored or serialized.

Fixes:

  1. Make sure you're using the correct data type in your Java model.

@ValueMapValue
@Optional
private boolean disable;

This will automatically treat "true" or "false" as a boolean, not a string.

  1. If using Sling Model Exporter, ensure the value is exported as a boolean:

@Exporter(name = "jackson", extensions = "json")
public class MyModel implements MyModelInterface {

    @ValueMapValue
    private boolean disable;

    @Override
    public boolean isDisable() {
        return disable;
    }
}

This will ensure your final JSON has:

"disable": true

or

"disable": false

— as actual booleans, not strings.

 

Hope that helps!
Regards,
Santosh


Santosh Sai

AEM BlogsLinkedIn