Aem 在下拉列表中填充值

Aem 在下拉列表中填充值,aem,day-cq,Aem,Day Cq,我有一个节点,其中有一个属性,其中包含下拉所需的json格式 [{"text":"Type1","value":"Type1"},{"text":"Type2","value":"Type2"},{"text":"333","value":"333"}] 我在component中有fie options.json.jsp和component.jsp <%@include file="/libs/foundation/global.jsp"%><% response.s

我有一个节点,其中有一个属性,其中包含下拉所需的json格式

[{"text":"Type1","value":"Type1"},{"text":"Type2","value":"Type2"},{"text":"333","value":"333"}]
我在component中有fie options.json.jsp和component.jsp

<%@include file="/libs/foundation/global.jsp"%><%
    response.setContentType("text/plain");
%><%
try {
        Node parent = resource.getResourceResolver().getResource("/etc/IgWebCMS/articletypes").adaptTo(Node.class);
        String json=parent.getProperty("json").getString();
        System.out.println("options json :::: "+json);
        }
     catch (RepositoryException re) {}
%>
        ${json}
在对话框下拉列表中,我提到了options属性:$PATH.options.json

但在我的对话框中,值没有得到填充。任何想法


谢谢

它将不起作用,因为您的
${json}
将始终是一个空字符串,因为您正在使用EL显示值,但从不首先设置值

要使用EL,应该在PageContext中设置该值,可以这样设置

<c:set var="json" value="<%= json %>" escapeXml="false" />
为了使代码正常工作,您可以直接使用脚本(如
)而不是
${json}
)输出json,也可以先将值设置为pageContext,然后使用
${json}
打印它

<> P>但如果您尝试使用Script,则应考虑在变量中声明变量,但在其外部使用时更改代码。
<%@ include file="/libs/foundation/global.jsp" %>
<%
response.setContentType("text/plain");
try {
    Node parent = resource.getResourceResolver().getResource("/etc/IgWebCMS/articletypes").
                        adaptTo(Node.class);
    out.print(parent.getProperty("json").getString());
} catch (RepositoryException re) {
    log.error(re.getMessage, re);
}
%>

最后,如果要将整个json保存为某个节点中的属性,那么可以直接提供保存该值的属性的路径,而不是编写json.jsp来获取值。 例如,您可以直接指定为
/etc/IgWebCMS/articletypes/json

pageContext.setAttribute("json", json);
<%@ include file="/libs/foundation/global.jsp" %>
<%
response.setContentType("text/plain");
try {
    Node parent = resource.getResourceResolver().getResource("/etc/IgWebCMS/articletypes").
                        adaptTo(Node.class);
    out.print(parent.getProperty("json").getString());
} catch (RepositoryException re) {
    log.error(re.getMessage, re);
}
%>