我有两个吊索模型:
@Model(adaptables = {SlingHttpServletRequest.class, Resource.class}, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class VideoGridItem {
@SlingObject
private Resource resource;
@SlingObject
private SlingHttpServletRequest slingHttpServletRequest;
@PostConstruct
public void initVideoGridItem() {
String[] selectors = slingHttpServletRequest.getRequestPathInfo().getSelectors();
insideGrid = selectors == null || selectors.length == 0 ? false : Arrays.stream(selectors).anyMatch("grid"::equals);
url = URLUtils.addHTMLIfPage(resource.getResourceResolver(), linkUrl);
}
}
和
@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class VideoListing {
private List<String> videoResourcePaths;
@PostConstruct
final void init() {
}
}
我使用 HTL 从视频列表组件中调用 VideoGridItem 组件(技术上是引用模型的资源):
<sly data-sly-list.videoResourcePath="${model.videoResourcePaths}">
<sly data-sly-resource="${videoResourcePath @ wcmmode='disabled', addSelectors='grid'}" data-sly-unwrap="true"></sly>
</sly>
现在,当我调试代码时,在 initVideoGridItem 内,slingHttpServletRequest 为空。公平地说,这个资源没有被直接请求,但我仍然需要能够访问选择器“网格”。有没有办法从 VideoGridItem.resource 做到这一点?