数据狡猾的资源错误处理 - AEM

时间:2017-03-03 06:19:54

标签: cq5 aem sightly

data-sly-resource标记允许以下列方式引用其他组件中的资源。

<article data-sly-resource="path/to/resource"></article>

内容作者已将path/to/resource视为对话框字段的一部分。如果内容作者选择了错误存在的路径,则内容作者无法访问页面,从而产生HTTP 500错误,并且没有其他方法可以在不转到CRX的情况下进行更正。在没有访问CRX的环境中,我们无法删除不正确的节点。日志中的例外是

Caused by: org.apache.sling.scripting.sightly.SightlyException: org.apache.sling.api.resource.ResourceNotFoundException: No resource found
at com.adobe.cq.sightly.WCMScriptHelper.includeResource(WCMScriptHelper.java:143)
at com.adobe.cq.sightly.WCMScriptHelper.includeResource(WCMScriptHelper.java:86)
at com.adobe.cq.sightly.internal.extensions.ResourceExtension.call(ResourceExtension.java:99)
at org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl.call(RenderContextImpl.java:89)

开箱即用reference component(/ libs/foundation/components/reference/reference.jsp)通过拥有一个catch块来处理这个问题,Content Author可以纠正路径。但是那个基于JSP的基础不是很明显。

有没有办法处理这个问题?

2 个答案:

答案 0 :(得分:2)

处理此问题的正确方法是通过Use-API对象尝试查找资源并处理任何异常:

IdentityDbContext

SLING-5811开始,可以将实际base.OnModelCreating(modelBuilder);传递给<article data-sly-use.helper="myHelper" data-sly-test="${helper.resource}" data-sly-resource="${helper.resource}"></article> ,对于旧版本的HTL / Sightly,您需要传递路径。

答案 1 :(得分:-1)

尝试这种语法,路径应该在EL表达式中给出:

<article data-sly-resource="${ @ path='path/to/resource'}"></article>