Access design_dialog(currentStyle) properties from within a Sling Model | Community
Skip to main content
Level 2
Jan 4, 2018 9:55 PM UTC
Solved

Access design_dialog(currentStyle) properties from within a Sling Model

Hi,

I am trying to access currentStyle properties from within a SlingModel. The SlingModel is being called from a  HTL component using data-sly-use that has a functional design_dialog and accessible currentStyle.

This was the only suggestion I could find using google:

@Inject @Source("script-bindings")

  private Style currentStyle;

and then

@PostConstruct

public void init() {

     String startLevel = currentStyle.get("startLevel",String.class); 

}

This isn't working. Can anyone tell me what I am doing wrong??

Thank you!

Ian

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
edubey
edubeyAccepted solution
Level 10
Jan 6, 2018 11:02 AM UTC

Irrespective of adapting to use Resource or Slinghttpservletrequest.

With latest sling jar, You can use below code to get access

@ScriptVariable

private Style currentStyle;

You can refer : https://github.com/Adobe-Marketing-Cloud/aem-core-wcm-components/blob/d4a9c2c7785f5d50e91dd2ebe145ace4a0bb7491/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ListImpl.java

7 replies

iannovicAuthor
Level 2
Jan 17, 2018 8:42 PM UTC

Hi Veena,

Sorry for the late reply.

I managed to try this with a new model that i created and it worked beautifully. Thank you for finding my problem!!!

Regards,

Ian

Translate
smacdonald2008
Level 10
Jan 6, 2018 11:04 PM UTC

Excellent answers Praveen and Veena!

Translate
edubey
edubeyAccepted solution
Level 10
Jan 6, 2018 11:02 AM UTC

Irrespective of adapting to use Resource or Slinghttpservletrequest.

With latest sling jar, You can use below code to get access

@ScriptVariable

private Style currentStyle;

You can refer : https://github.com/Adobe-Marketing-Cloud/aem-core-wcm-components/blob/d4a9c2c7785f5d50e91dd2ebe145ace4a0bb7491/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/ListImpl.java

Translate
VeenaVikraman
New Participant
Jan 5, 2018 7:14 PM UTC

Can you try with SlingHttpServletRequest.class and let me know if this works.

Translate
iannovicAuthor
Level 2
Jan 5, 2018 5:43 PM UTC

No I wasn't using @Model(adaptables = SlingHttpServletRequest.class), I had

@Model(adaptables = Resource.class) instead. that was probably my issue then?

Translate
VeenaVikraman
New Participant
Jan 5, 2018 5:40 PM UTC

I would suggest you to use the above one . It works for me

Are you using @Model(adaptables = SlingHttpServletRequest.class)

@Model(adaptables = SlingHttpServletRequest.class) public class SampleModel{       private final Logger LOG = LoggerFactory.getLogger(getClass());       @Inject      SlingHttpServletRequest request;       @Inject      private Page currentPage;       @Inject      @Source("script-bindings")      private Style currentStyle;  
Translate
iannovicAuthor
Level 2
Jan 5, 2018 4:42 PM UTC

Update:

I decided to extend WCMUse instead, this class has access to getCurrentStyle(). I am still interested if anyone has a way to make this work with a sling model though!

Translate