Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

Extend AEM OOTB Core List Sling Model to add an extra field through dialog

Avatar

Level 1

Hi All,

 

I have a requirement where I have to extend List core component dialog & sling model to add one extra filed to be added along with other 3 fields available under OOTB core list component. I have added a text field under "Fixed List" section along with other 3 existing fields. Last field in the below screenshot -

arana1_0-1699949779051.png

 

These highlighted fields in yellow, I need to get them added within the list result beings provided by OOTB list sling model. I tried to achieve the same by Sling Delegation Pattern but unable to get it working. I created a class "PageListImpl" implementing the List class & tried to override Collection<ListItem> getListItems(). Since I just needed to add an extra fields within the existing list item, I didn't intend to rewrite everything again but rely on the core List implementation. I planned to create an implementation of ListItem class (class PageListItemImpl implements ListItem), add the extra required field being passed through dialog. Prepare a list of this custom PageListItemImpl and return it back from the PageListImpl class. But I am seeing errors while trying to return this list from the overriden function.


This is how my PageListImpl looks like -

 

@Model(adaptables = SlingHttpServletRequest.class, adapters = List.class, resourceType = "test/components/core/list",
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class PageListImpl implements List {

static final Logger LOG = LoggerFactory.getLogger(PageListImpl.class);

@Self
@Via(type = ResourceSuperType.class)
@Delegate(excludes = DelegationExclusion.class)
private List listModel;

@Getter
@ChildResource(name = "static")@Via("resource")
private java.util.List<StaticList> staticList;

private interface DelegationExclusion {
Collection<ListItem> getListItems();
}

private java.util.List<PageListItemImpl> pageListItemList = new ArrayList<>();
private Map<String, String> map = new HashMap<>();

@Override
public @NotNull
Collection<ListItem> getListItems() {
for(StaticList str : staticList){
if(str != null){
map.put(str.getLinkURL(), str.getProductTracking());
}
}
for(ListItem item : listModel.getListItems()){
PageListItemImpl pageListItem = new PageListItemImpl();
pageListItem.setLink(item.getLink());
pageListItem.setDescription(item.getDescription());
pageListItem.setPath(item.getPath());
pageListItem.setName(item.getName());
pageListItem.setTeaserResource(item.getTeaserResource());
pageListItem.setTitle(item.getTitle());
pageListItem.setData(item.getData());
pageListItem.setId(item.getId());
pageListItem.setURL(item.getDescription());
pageListItem.setProductTracking(map.get(item.getPath()));
pageListItemList.add(pageListItem);

}
if(pageListItemList != null && pageListItemList.size() > 0){
//return pageListItemList;
}
return listModel.getListItems();
}
}

Any pointers would be highly appreciated. Thank you.

 

@kautuk_sahni @arunpatidar @kiran5 @lukasz-m @BrianKasingli @Tushaar_Srivastava1 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @arana1 
Could you please check below PR, I extended teaser component to update multifield with additional field

https://github.com/arunpatidar02/aemaacs-aemlab/pull/29 



Arun Patidar

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @arana1 
Could you please check below PR, I extended teaser component to update multifield with additional field

https://github.com/arunpatidar02/aemaacs-aemlab/pull/29 



Arun Patidar

Avatar

Administrator

@arana1 Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni