Search code examples
htmlspring-bootuser-interfacecheckboxfreemarker

Freemarker how to select checkboxes on UI send by backend?


Have following data passed from backend:

ALL_CONFIGS: {callDigitalIo=true, controllerId=1, numberPlatesHashSalt=..., numberPlatesShouldBeHashed=false, parkingStatusShouldBeChecked=true}

Where boolean params should be displayed like input element with type=checkbox.

Here is how I handle it on UI page (.ftl):

<div>
    <label class="col-form-label">
        Parking Status Should Be Checked:
        <input type="checkbox" class="form-check-input ml-2"
               id="parkingStatusShouldBeChecked" name="parkingStatusShouldBeChecked"
               <#if parkingStatusShouldBeChecked??>checked="checked"</#if>
        />
    </label>
</div>

However, checkboxes are all selected:

enter image description here

Number Plates Should be Hashed should not be selected.

How to select only true variables?


Solution

  • After huge research I found solution for this issue:

    <div>
        <label class="col-form-label">
            Parking Status Should Be Checked:
            <input type="checkbox" class="form-check-input ml-2"
                   id="parkingStatusShouldBeChecked"
                   <#if parkingStatusShouldBeChecked == "true">checked</#if>
            />
        </label>
    </div>
    

    It works fine.