Expand my Community achievements bar.

SOLVED

GenericListItem cannot be resolved to a type

Avatar

Level 5

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?
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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();
    // ...
}

 

View solution in original post

2 Replies

Avatar

Community Advisor

@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-gene...

 

Avatar

Correct answer by
Community Advisor

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();
    // ...
}