0

I have an OSGi service that needs to access values stored by a component in it's design dialog.

Since I don't have access to the currentStyle value. I've attempted to access that Style object by instantiating it myself, with little luck.

My current code to access it from the the ServletRequest is

SlingHttpServletRequest resource = (SlingHttpServletRequest)request;
ComponentContext componentContext = WCMUtils.getComponentContext(resource);
Page page = componentContext.getPage();
Design design = page.adaptTo(Design.class);
return design.getStyle(componentContext.getCell())

At this point there is a style object, but no values get returned from it.

JE Bailey
  • 727
  • 7
  • 25
  • What does the resource object in the first line represent? It seems like this code is way more complex than necessary. For example, if the resource is a page, you can just say resource.adpatTo(Page.class). – ryanlunka Jul 22 '14 at 00:34
  • @ryanlunka At least in 5.5 if the resource is for a node for a component on the page, it can't be adapted to a Page. The resource I'm working with is a component level resource. – JE Bailey Jul 22 '14 at 14:55

1 Answers1

0

I found this code to return the correct Style object

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());
JE Bailey
  • 727
  • 7
  • 25