AEM吊索模型--Multifield Links组件,MissingElementsException:无法注入所有必填字段

问题描述 投票:-1回答:3

AEM吊索模型--Multifield链接组件:

MissingElementsException:无法注入所有必填字段

我正在尝试创建一个multifield链接(URL)组件 - 外部和内部链接。请参阅getpageURL()以了解。

见下图:

@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;
}

}

java aem cq5 sightly htl
3个回答
0
投票

请检查天气,你可以获得pagePath值,如果不是必须使用@Optional注释。

使用以下链接作为参考

[https://sling.apache.org/documentation/bundles/models.html][1]

谢谢,Kiran


0
投票
      protected String init() {
    pagePath = getPageURL(pagePath);
    return pagePath;  //<--------------added this
   }

和@optional kiran说的....


0
投票

你在这里错过了一个@Optional:

...

@Inject
@Named("items")
@Optional                      //<--- THIS
public Resource pagePathMF;

...
© www.soinside.com 2019 - 2024. All rights reserved.