1

I need an understanding of what wcmusepojo and sling models mean? I mean I've read that these implementations are to bring together your component and the back-end implementation but what exactly is done in these (wcmusepojo and sling models) vs what is done inside a component sightly code?

Also what is the difference between using wcmusepojo and using sling models?

Vishal--JAVA--CQ
  • 188
  • 1
  • 2
  • 18

1 Answers1

2

Sling's implementation of HTL/Sightly has several ways of resolving business-logic classes to be used in HTL scripts, among these:

  • Regular POJOs
  • Sling Models

Regular POJOs that extend WCMUsePojo (Javadoc) implement the Use interface and are initialised with the scripting bindings, providing convenience methods for accessing commonly used objects (request, resource, properties, page etc).

Sling Models can also be used outside HTL/Sightly, thus making your business-logic more reusable. They are managed by Sling and can be injected references to other objects using annotations and reflection.

You can find more information and PROs and CONs for each at https://sling.apache.org/documentation/bundles/scripting/scripting-htl.html#picking-the-best-use-provider-for-a-project

Vlad
  • 10,602
  • 2
  • 36
  • 38
  • Thanks. But Do you imply that the WCMUSEPOJO cannot be (or should not be) injected into other objects? Also is there a clear bifercation of what should be done in HTL and what should be done in the back-end classes? – Vishal--JAVA--CQ Oct 03 '18 at 02:24
  • @Vishal--JAVA--CQ Of course POJOs can be reused in other contexts as well, you just have to manage instantiation and initialisation (passing the bindings) yourself. – Vlad Oct 03 '18 at 06:06