GenericListItem cannot be resolved to a type | Community
Skip to main content
Level 4
March 24, 2023
Solved

GenericListItem cannot be resolved to a type

  • March 24, 2023
  • 2 replies
  • 1566 views

I am working on a servlet that will get a page path as a query parameter. Page path will be sth like /content/a/b/c/08/03

I need to use Generic List to create a map between the ID and its value as we don't want to be dependent on builds to modify the list items.

The code snippet is 

Page lobGenericList = pageManager.getPage("/etc/acs-commons/lists/lob");
        GenericList lobList = lobGenericList.adaptTo(GenericList.class);
        assert lobList != null;
        List<GenericListItem> lobListItems = lobList.getItems();
        String lobValue = lobListItems.lookupTitle(lobId);
        logger.info("LOB value mapped to list is {}", lobValue);
In the above code, I'm trying to get the lobValue by using GenericListItem class. But I'm getting error "Cannot be resolved to a type". 
 
ACS Commons version -> 5.7.0
 
What can be the issue?
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by lukasz-m

Hi @goyalkritika,

I see 2 issues in your code, check the details below.

  1. List<GenericListItem> lobListItems = lobList.getItems();

    This line is incorrect. ACS Commons does not provide class GenericListItem. What is provided is an interface Item which is inner interface of GenericList interface. This is also the reason why you are getting Cannot be resolved to a type. You can find all the details in terms of api and implementation under:

    1. Interfaces definition:
      1. com.adobe.acs.commons.genericlists.GenericList
      2. com.adobe.acs.commons.genericlists.GenericList.Item
    2. Implementation:
      1. com.adobe.acs.commons.genericlists.impl.GenericListImpl
      2. com.adobe.acs.commons.genericlists.impl.GenericListImpl.ItemImpl
    3. General api description https://adobe-consulting-services.github.io/acs-aem-commons/features/generic-lists/index.html
  2. String lobValue = lobListItems.lookupTitle(lobId);

    Unfortunately this is also wrong. Base on above link I have shared and contract provided as part of interfaces, Item is providing 3 methods getTitle(), getTitle(Locale locale) and getValue(). lookupTitle(String value) is method from GenericList.

If you want to retrieve title of specific list element having it's id you can simply use code like this:

 

import com.adobe.acs.commons.genericlists.GenericList; // place for some other code PageManager pageManager = resourceResolver.adaptTo(PageManager.class); Page lobGenericList = pageManager.getPage("/etc/acs-commons/lists/lob"); GenericList lobList = lobGenericList .adaptTo(GenericList.class); String lobValue = lobList.lookupTitle(lobId);

 

If you want to access all the items and do some processing against each, this example shows this:

 

import com.adobe.acs.commons.genericlists.GenericList; PageManager pageManager = resourceResolver.adaptTo(PageManager.class); Page page = pageManager.getPage("/etc/acs-commons/lists/lob"); GenericList genericList = page.adaptTo(GenericList.class); List<GenericList.Item> items = genericList.getItems(); for (GenericList.Item item : items) { String title = item.getTitle(); String value = item.getValue(); // ... }

 

2 replies

Saravanan_Dharmaraj
Community Advisor
Community Advisor
March 24, 2023

@goyalkritika Please check the sample code given using resource API in the below post

 

Resource resource = resourceResolver.getResource("/etc/acs-commons/lists/cities/jcr:content/list"); if (Objects.nonNull(resource)) { citymap = new HashMap<String, String>(); @NotNull Iterable<Resource> children = resource.getChildren(); for (Resource childResource : children) { String title = childResource.getValueMap().get("jcr:title", String.class); String nodevalue = childResource.getValueMap().get("value", String.class); citymap.put(nodevalue, title); } }

 

 

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-can-we-populate-a-generic-list-in-form-of-dropdown-in-search/td-p/462316

 

lukasz-m
Community Advisor
lukasz-mCommunity AdvisorAccepted solution
Community Advisor
March 26, 2023

Hi @goyalkritika,

I see 2 issues in your code, check the details below.

  1. List<GenericListItem> lobListItems = lobList.getItems();

    This line is incorrect. ACS Commons does not provide class GenericListItem. What is provided is an interface Item which is inner interface of GenericList interface. This is also the reason why you are getting Cannot be resolved to a type. You can find all the details in terms of api and implementation under:

    1. Interfaces definition:
      1. com.adobe.acs.commons.genericlists.GenericList
      2. com.adobe.acs.commons.genericlists.GenericList.Item
    2. Implementation:
      1. com.adobe.acs.commons.genericlists.impl.GenericListImpl
      2. com.adobe.acs.commons.genericlists.impl.GenericListImpl.ItemImpl
    3. General api description https://adobe-consulting-services.github.io/acs-aem-commons/features/generic-lists/index.html
  2. String lobValue = lobListItems.lookupTitle(lobId);

    Unfortunately this is also wrong. Base on above link I have shared and contract provided as part of interfaces, Item is providing 3 methods getTitle(), getTitle(Locale locale) and getValue(). lookupTitle(String value) is method from GenericList.

If you want to retrieve title of specific list element having it's id you can simply use code like this:

 

import com.adobe.acs.commons.genericlists.GenericList; // place for some other code PageManager pageManager = resourceResolver.adaptTo(PageManager.class); Page lobGenericList = pageManager.getPage("/etc/acs-commons/lists/lob"); GenericList lobList = lobGenericList .adaptTo(GenericList.class); String lobValue = lobList.lookupTitle(lobId);

 

If you want to access all the items and do some processing against each, this example shows this:

 

import com.adobe.acs.commons.genericlists.GenericList; PageManager pageManager = resourceResolver.adaptTo(PageManager.class); Page page = pageManager.getPage("/etc/acs-commons/lists/lob"); GenericList genericList = page.adaptTo(GenericList.class); List<GenericList.Item> items = genericList.getItems(); for (GenericList.Item item : items) { String title = item.getTitle(); String value = item.getValue(); // ... }