AEM sling model --Multifield
Links component :
MissingElementsException: Could not inject all required fields
I am trying to create a multifield
link(URL) component - EXTERNAL AND INTERNAL LINKS. See getpageURL()
for understanding.
See the image below:
@Model(adaptables = Resource.class)
public class Links_Bean {
@Inject
private String pagePath;
@PostConstruct
protected void init() {
pagePath = getPageURL(pagePath);
}
public static String getPageURL(String pagePath) {
if (pagePath.isEmpty() || (pagePath.equals(null))) {
return null;
} else if (pagePath.startsWith("/content")) {
return pagePath.concat(".html");
} else if (pagePath.startsWith("http://") || pagePath.startsWith("https://") || pagePath.startsWith("www")) {
return pagePath;
}
return pagePath;
}
public String getPagePath() {
return pagePath;
}
public void setPagePath(String pagePath) {
this.pagePath = pagePath;
}
}
package com.hcl.aem.core.models;
@Model(adaptables = Resource.class)
public class MF_newMethod {
@Inject
@Named("items")
public Resource pagePathMF;
public List<Links_Bean> links = new ArrayList<Links_Bean>();
@PostConstruct
protected void init() {
if (pagePathMF != null) {
links = getPageList(links, pagePathMF);
}
}
public static List<Links_Bean> getPageList(List<Links_Bean> array, Resource resource) {
if (resource != null) {
Iterator<Resource> linkResource = resource.listChildren();
while (linkResource.hasNext()) {
Links_Bean lb = linkResource.next().adaptTo(Links_Bean.class);
array.add(lb);
}
}
return array;
}
public List<Links_Bean> getLinks() {
return links;
}
}