Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

AEM Cloud Service - Sort PathField Picker pages Alphabetically | AEM Community Blog Seeding




AEM Cloud Service - Sort PathField Picker pages Alphabetically by Sreekanth Choudry Nalabotu


AEM Cloud Version 2022.4.7138.20220427T075748Z-220401
PathField picker shows pages in the order they exist in CRX. This extension is to show them in Alphabetical order...

1) Create the project...

mvn -B org.apache.maven.plugins:maven-archetype-plugin:3.2.1:generate -D archetypeGroupId=com.adobe.aem
-D archetypeArtifactId=aem-project-archetype -D archetypeVersion=36 -D aemVersion=cloud
-D appTitle="Experience AEM Path Field Sort" -D appId="eaem-pathfield-sort" -D groupId="apps.experienceaem.sites"
-D frontendModule=none -D includeExamples=n -D includeDispatcherConfig=n

2) Add filter apps.experienceaem.sites.core.filters.PathFieldSortFilter to sort the nodes for PathField picker ...

package apps.experienceaem.sites.core.filters;

import com.adobe.granite.ui.components.ds.AbstractDataSource;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;

import com.adobe.granite.ui.components.ds.DataSource;

import javax.servlet.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

service = Filter.class,
immediate = true,
name = "Experience AEM PathField Sort Filter",
property = {
Constants.SERVICE_RANKING + ":Integer=-99",
public class PathFieldSortFilter implements Filter {
public static String DATA_SOURCE_NAME = DataSource.class.getName();

public void init(FilterConfig filterConfig) throws ServletException {

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
chain.doFilter(new PathFieldSlingServletRequestWrapper((SlingHttpServletRequest) request), response);

public void destroy() {

private class PathFieldSlingServletRequestWrapper extends SlingHttpServletRequestWrapper {
public PathFieldSlingServletRequestWrapper(final SlingHttpServletRequest request) {

public Object getAttribute(String attrName) {
if (!PathFieldSortFilter.DATA_SOURCE_NAME.equals(attrName)) {
return super.getAttribute(attrName);

DataSource ds = (DataSource) super.getAttribute(attrName);

if (ds == null) {
return ds;

final List sortedList = new ArrayList();
Iterator items = ds.iterator();

while (items.hasNext()) {


ds = new AbstractDataSource() {
public Iterator iterator() {
return sortedList.iterator();

return ds;

Read Full Blog

AEM Cloud Service - Sort PathField Picker pages Alphabetically


Please use this thread to ask the related questions.

0 Replies