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
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @goyalkritika,
I see 2 issues in your code, check the details below.
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:
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();
// ...
}
@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);
}
}
Hi @goyalkritika,
I see 2 issues in your code, check the details below.
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:
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();
// ...
}
Views
Likes
Replies
Views
Likes
Replies