我有一个OSGi服务,需要访问组件在其设计对话框中存储的值。
因为我无法访问currentStyle值。我试图通过自己实例化来访问该Style对象,运气不佳。
我目前从ServletRequest访问它的代码是
SlingHttpServletRequest resource = (SlingHttpServletRequest)request;
ComponentContext componentContext = WCMUtils.getComponentContext(resource);
Page page = componentContext.getPage();
Design design = page.adaptTo(Design.class);
return design.getStyle(componentContext.getCell())
此时有一个样式对象,但没有从它返回任何值。
答案 0 :(得分:0)
我发现此代码返回正确的Style对象
SlingHttpServletRequest request = (SlingHttpServletRequest)adaptable;
Designer designer = (Designer)request.getResourceResolver().adaptTo(Designer.class);
ComponentContext componentContext = WCMUtils.getComponentContext(request);
Page page = componentContext.getPage();
Design design = designer.getDesign(page);
return design.getStyle(componentContext.getCell());