i am trying to extend checkbox and add a descreption and value to each item
the thing is I've tried to connect the java with the dialog but its not working
what i did wrong
html
<div data-sly-use.valueAndDescription="com.adobe.aem.guides.wknd.core.models.ValuesAndDescriptionsModel">
<input type="checkbox">
<h2>${valueAndDescription.fieldLabel}</h2>
<p>${valueAndDescription.fieldDescription}</p>
<ul data-sly-list="${valueAndDescription.valuesAndDescriptions}">
<li>
<p>Value:</p> ${item.value}<br>
<p>Description:</p> ${item.description}
</li>
</ul>
</div>
content.xml
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
cq:icon="text"
jcr:primaryType="cq:Component"
jcr:title="Adaptive Form CheckBox"
sling:resourceSuperType="/libs/fd/af/components/guidecheckbox"
componentGroup="Adaptive Form"/>
dialog
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:granite="http://www.adobe.com/jcr/granite/1.0"
xmlns:cq="http://www.day.com/jcr/cq/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Adaptive Form CheckBox field"
sling:resourceType="cq/gui/components/authoring/dialog"
>
<content
granite:class="cmp-adaptiveform-checkbox__editdialog"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<valuesAndDescriptions
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/multifield"
fieldLabel="Values and Descriptions"
name="./valuesAndDescriptions"
fieldDescription="Add values and their descriptions for the checkbox options.">
<field
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<value
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldLabel="Value"
name="value"
required="{Boolean}true"/>
<description
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldLabel="Description"
name="description"
fieldDescription="Add a description for the value."
/>
</items>
</field>
</valuesAndDescriptions>
</items>
</content>
</jcr:root>
Interface
package com.adobe.aem.guides.wknd.core.models;
import com.adobe.aem.guides.wknd.core.models.impl.ValueAndDescriptionImpl;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import java.util.List;
import java.util.Map;
public interface ValuesAndDescriptionsModel {
public String getFieldLabel();
public String getName();
public String getFieldDescription();
public String getValue();
abstract List<Map<String, String>> getValuesAndDescriptions();
}
java
package com.adobe.aem.guides.wknd.core.models.impl;
import com.adobe.aem.guides.wknd.core.models.ValuesAndDescriptionsModel;
import com.adobe.cq.wcm.core.components.util.AbstractComponentImpl;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.SlingObject;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Model(adaptables = SlingHttpServletRequest.class,
adapters = {ValuesAndDescriptionsModel.class},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL,
resourceType=ValueAndDescriptionImpl.RESOURCE_TYPE)
public class ValueAndDescriptionImpl extends AbstractComponentImpl implements ValuesAndDescriptionsModel{
@SlingObject
private Resource resource;
@ValueMapValue
private String[] valuesAndDescriptions;
@ValueMapValue
private String value;
public static final String RESOURCE_TYPE = "dow-platform/components/forms/checkbox";
@Override
public String getValue() {
return this.value;
}
@Override
public String getFieldLabel() {
return resource.getValueMap().get("fieldLabel", String.class);
}
@Override
public String getName() {
return resource.getValueMap().get("name", String.class);
}
@Override
public String getFieldDescription() {
return resource.getValueMap().get("fieldDescription", String.class);
}
@Override
public List<Map<String, String>> getValuesAndDescriptions() {
List<Map<String, String>> result = new ArrayList<>();
for (String valueAndDescription : valuesAndDescriptions) {
String[] parts = valueAndDescription.split("\\|");
if (parts.length == 2) {
Map<String, String> entry = new HashMap<>();
entry.put("value", parts[0]);
entry.put("description", parts[1]);
result.add(entry);
}
}
return result;
}
}