Why we extends WCMUsePojo class while working with AEM?

谁说我不能喝 提交于 2019-12-01 08:41:52

Because in AEM’s component development mechanism, you likely need a way to provide back-end logic to components.

That's because Sightly (when used as a rendering script language instead of the JSP pages) is on purpose a limited template language that allows to do only small basic operations, and the heavy lifting logic should be done inside a Java class or a server-side JS (that you refer using the data-sly-use element inside the Sightly script).

This provide better decoupling of the business logic and so your code will be more easily maintainable and also easier to debug.

In order to abstract component Java class with page context or binding objects, previously Adobe’s WCMUse was used, or a custom implementation of Use class. If your working with AEM 6.1 or 6.2 WCMUsePojo class is used (or even Sling Models). With the release of AEM 6.3 and AEM Core WCM Components, we see that using Sling Models have been advocated by Adobe as the best practice.

While the previous answer gives a pretty good explanation, I will write my own - brief one:

  1. You can use simple Pojo (do not extend any Adobe's class) with java-use-api. But in this case, you will not be able to easily access resources/services.
  2. You can extend WCMUsePojo to get the ability to use resources/services.
  3. Also, you can go with Sling Models way which will give you more flexibility.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!