Hi @nandheswara , It all depend on complexity on your use case/Multifield. I am sharing a pseudo code having 3 fields in multifield and in sling model it handling using MAP. Update field names as per need. I will also add links to complete files
Dialog(only multifield pseudo code. Will leave link to complete dialog file)
<bookdetailswithmap
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/multifield"
composite="{Boolean}true"
fieldDescription="Books Details"
fieldLabel="Book Details"
required="{Boolean}false">
<field
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container"
emptyText="Books Details"
name="./bookdetailswithmap">
<items jcr:primaryType="nt:unstructured">
<book
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
emptyText="Book Name"
fieldLabel="Book Name"
name="./bookname"/>
<subject
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
emptyText="Book Subject"
fieldLabel="Book Subject"
name="./booksubject"/>
<published
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
emptyText="Publish Year"
fieldLabel="Publish Year"
name="./publishyear"/>
</items>
</field>
</bookdetailswithmap>
Sling Model(Only method which return multifield values. get resource using annotation)
public List<Map<String, String>> getBookDetailsWithMap() {
List<Map<String, String>> bookDetailsMap=new ArrayList<>();
try {
Resource bookDetail=componentResource.getChild("bookdetailswithmap");
if(bookDetail!=null){
for (Resource book : bookDetail.getChildren()) {
Map<String,String> bookMap=new HashMap<>();
bookMap.put("bookname",book.getValueMap().get("bookname",String.class));
bookMap.put("booksubject",book.getValueMap().get("booksubject",String.class));
bookMap.put("publishyear",book.getValueMap().get("publishyear",String.class));
bookDetailsMap.add(bookMap);
}
}
}catch (Exception e){
LOG.info("\n ERROR while getting Book Details {} ",e.getMessage());
}
LOG.info("\n SIZE {} ",bookDetailsMap.size());
return bookDetailsMap;
}
Sightly (pseudo code) to print multifield values. Update as per your need.
<div data-sly-list.item="${books.bookDetailsWithMap}">
---------------Book : ${itemList.count}--------------
<p> Book : <b>${item.bookname} </b></p>
<p> Subject : <b>${item.booksubject}</b> </p>
<p> Publish : <b>${item.publishyear}</b> </p>
</div>
Sling Model - https://github.com/aemgeeks1212/aemgeeks/blob/master/core/src/main/java/com/aem/geeks/core/models/impl/AuthorBooksImpl.java
Component - https://github.com/aemgeeks1212/aemgeeks/tree/master/ui.apps/src/main/content/jcr_root/apps/aemgeeks/components/content/author-books
If you are interested. Links to video tutorials.
Multifield - https://youtu.be/TJaAdbkyPJQ
Nested Multifield - https://youtu.be/Lm6o5JDNiqs
Validation for Multifield - https://youtu.be/tsd8s8UMBRY