Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

If I am making the checkbox default checked, on some existing pages checkbox is not showing checked

Avatar

Level 1

If I am making the checkbox default checked using coral2 checkbox field,

 

<enableBanner
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/checkbox"
fieldDescription="Check if shorter banner is required."
listener="toggle.checkboxShorterBanner"
name="./enableBanner"
text="Shorter Banner"
uncheckedValue="false"
value="true"
defaultChecked="{Boolean}true"/>

and in SlingModel using it

@ValueMapValue
@Default(booleanValues = true)
private boolean enableBanner;

Sightly code
<div id="${properties.isBanner ? 'main_banner':''}"
class="${bannerPowerModel.enableBanner? shortHeroClass : ''}">
I want to add shortHeroClass if it is checked otherwise no


I can see the difference in html where it is coming as checked by default
<div class="coral-Form-fieldwrapper coral-Form-fieldwrapper--singleline"><label class="coral-Checkbox coral-Form-field">
<input type="checkbox" name="./shorterBanner" value="true" data-validation="" checked="" class="coral-Checkbox-input" data-listener="toggle.checkboxShorterBanner">

where it is not coming as checked by default, checked="" is not coming in html
<div class="coral-Form-fieldwrapper coral-Form-fieldwrapper--singleline"><label class="coral-Checkbox coral-Form-field">
<input type="checkbox" name="./enableBanner" value="true" data-validation="" class="coral-Checkbox-input" data-listener="toggle.checkboxShorterBanner">
But on this page if I am dragging dropping this component, then it is showing checkbox checked by default
I also want to show hide tab based on checkbox selection
 
 
 
Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @vineetgupta,

  • The defaultChecked="{Boolean}true" attribute only sets the initial value when no value is stored in the JCR.

  • If an existing page already has the property enableBanner (even as false or empty), the dialog will render based on the stored value, not the defaultChecked value.

Here is what coming in my mind:

1. Fix existing content nodes

To force all existing pages to have enableBanner=true (checked by default), you can run a JCR content update (via Groovy script, ACS Commons Bulk Editor, or a query).
Example Groovy script:

def rootPath = "/content/your-site"
def nodes = getNode(rootPath).recurse().findAll { it.hasNode("enableBanner") == false }
nodes.each {
    it.setProperty("enableBanner", true)
}

This ensures that older pages have enableBanner set correctly.

2. Use @Default(booleanValues = true) in SlingModel

You are already using:

@ValueMapValue
@Default(booleanValues = true)
private boolean enableBanner;

This is good - it ensures that if the property is missing in JCR, the model returns true.
However, in Sightly/HTL, you should reference bannerPowerModel.enableBanner instead of properties.isBanner to ensure the model's logic takes precedence.

 


Santosh Sai

AEM BlogsLinkedIn


View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @vineetgupta,

  • The defaultChecked="{Boolean}true" attribute only sets the initial value when no value is stored in the JCR.

  • If an existing page already has the property enableBanner (even as false or empty), the dialog will render based on the stored value, not the defaultChecked value.

Here is what coming in my mind:

1. Fix existing content nodes

To force all existing pages to have enableBanner=true (checked by default), you can run a JCR content update (via Groovy script, ACS Commons Bulk Editor, or a query).
Example Groovy script:

def rootPath = "/content/your-site"
def nodes = getNode(rootPath).recurse().findAll { it.hasNode("enableBanner") == false }
nodes.each {
    it.setProperty("enableBanner", true)
}

This ensures that older pages have enableBanner set correctly.

2. Use @Default(booleanValues = true) in SlingModel

You are already using:

@ValueMapValue
@Default(booleanValues = true)
private boolean enableBanner;

This is good - it ensures that if the property is missing in JCR, the model returns true.
However, in Sightly/HTL, you should reference bannerPowerModel.enableBanner instead of properties.isBanner to ensure the model's logic takes precedence.

 


Santosh Sai

AEM BlogsLinkedIn