【发布时间】:2016-01-18 03:58:47
【问题描述】:
在 CQ5 中,项目加载路径字段允许作者提供一个 URL,从该 URL 加载下拉列表/复选框组等中可用的选项。但它实际上是如何工作的?
编辑:我使用的是 5.6.1 版本,以防万一
以下是我所知道的:
1) 我知道 CQ5 中的组件对话框将其内容存储在:
/content/page/jcr:content/<component node>
在这种情况下,它存储在一个名为 './optionLoadPath' 的属性中:
2)我知道在任何组件(例如,复选框组件)中,要显示的值列表通过以下方式加载到字符串列表中:
编辑 2:@awadheshv 刚刚指出要显示的值列表实际上是使用 FormsHelper.getOptions() 加载的。如果是这样,getValueAsList 是做什么的?
final List<String> values = FormsHelper.getValuesAsList(slingRequest, resource);
在使用 forloop 显示之前:
for (String v : displayValues.keySet()) {
final String t = displayValues.get(v);
final String currentId = id + "-" + i;
%><div class="form_row"><%
LayoutHelper.printTitle(currentId, t, false, true, out);
%><div class="form_rightcol"><%
String checked = "";
if (values.contains(v)) {
checked = " checked=\"checked\"";
}
%><input class="<%= FormsHelper.getCss(properties, "form_field form_field_checkbox") %>" type="checkbox"
id="<%= StringEscapeUtils.escapeHtml4(currentId) %>" name="<c:out value="<%= name %>"/>"
value="<c:out value="<%= v %>"/>" <%= checked %> /> <c:out value="<%= t %>" />
</div>
</div><%
i++;
}
3) 我也知道 FormsHelper.getValuesAsList 只是调用 FormsHelper.getValues 并将返回的数组转换为列表。
public static List<String> getValuesAsList(final SlingHttpServletRequest request, final Resource elementResource) {
final String[] values = getValues(request, elementResource);
if ( values == null ) {
return Collections.emptyList();
}
return Arrays.asList(values);
}
但我不明白一切是如何结合在一起的。在什么时候/如何将 optionLoadPath 中的项目列表传递给 FormsHelper?
此外,如果我想在默认情况下加载值,我该怎么做呢?例如,假设有一个国家列表我想加载到组件中。我仍然希望用户能够根据需要将 URL 更改为不同的国家/地区列表,但我希望在将组件放入页面后立即加载默认列表。我该怎么做呢?
【问题讨论】: