servletsaemsightlywcmsling-models

Sling models vs WCMUSEPOJO


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?


Solution

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

    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