简体   繁体   English

不在 /content 下的组件的 AEM servlet?

[英]AEM servlet for a component that is not under /content?

My goal is to create a token whenever a page is rendered that contains a component called someTeaser.我的目标是在呈现包含名为 someTeaser 的组件的页面时创建一个令牌。 This someTeaser component renders in the template after the content and before the footer and is not editable.这个 someTeaser 组件在内容之后和页脚之前呈现在模板中,并且不可编辑。 It is configured fixed in the template structure.它在模板结构中被固定配置。

The problem appears when I want to create a servlet for someTeaser.当我想为 someTeaser 创建一个 servlet 时,问题就出现了。 This component is not in the Content Repository crxde.此组件不在内容存储库 crxde 中。

@SlingServletResourceTypes(
        resourceTypes = {Constants.ResourceTypes.SOME_TEASER},
        selectors = {"token"},
        extensions = Constants.Extensions.JSON
)

The resource for this component is /conf/xx/settings/wcm/templates/someTemplate/structure/jcr:content/root/main/container/someTeaser .该组件的资源是/conf/xx/settings/wcm/templates/someTemplate/structure/jcr:content/root/main/container/someTeaser This resource cannot be resolved in publish.此资源无法在发布中解析。 It is not under content but rather under conf.它不在内容下,而是在 conf 下。

Request URL: https://publish_server/conf/xxx/settings/wcm/templates/someTemplate/structure/jcr:content/root/main/...

Request Method: GET

Status Code: 404 Not Found

An alternative solution would be to use define resourceTypes = {Constants.ResourceTypes.PAGE} in the servlet but then every page will be checked for the selector token.另一种解决方案是在 servlet 中使用 define resourceTypes = {Constants.ResourceTypes.PAGE}但随后将检查每个页面的选择器标记。

Can someone suggest an alternative solution for the task?有人可以为该任务提出替代解决方案吗?

I was able to request the token for the container that is avaliable in the JCR repository.我能够为 JCR 存储库中可用的容器请求令牌。

String containerPath =  PathBuilder.with(currentPage.getPath())
        .slash(AemConstants.JCR_CONTENT)
        .slash("root/main/container")
        .build();

and resolve the container url nicely using resourceResolver.map(path) .并使用resourceResolver.map(path)很好地解析容器 url 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM