recent post on Composite Multifield support in HTL. His code sample clocks in at 60 lines, the same functionality in JSP is only 12 lines:
<c:forEach var="company" items="${sling:listChildren(resource)}">
<li>
<ul>
<c:forEach var="department" items="${sling:listChildren(company)}">
<li>
<strong>Department: </strong> ${sling:encode(department.valueMap.name,'HTML')} <br/>
<strong>Manager: </strong> ${sling:encode(department,'HTML')}
</li>
</c:forEach>
</ul>
</li>
</c:forEach>
It’s certainly not anything Ahmed did wrong; his code is exemplary, HTL by design puts training wheels on our development resulting in verbose, redundant code.
The color in the lines mentality of HTL has lead to what I call “Death by Models”. Since you have to write a Model for everything but the simplest use cases, HTL projects become littered with similar, but different models for practically every component. Hours of wasted time writing boilerplate code and now if you want to make a change you have to update the corresponding Sling models, not just the component scripts.
Additionally, HTL makes it harder for new developers to learn to develop on AEM since it is not used outside AEM. JSPs have been around since 1999 and are pretty widely understood and documented, HTL… not so much. Even if the direction was to use another of the plethora of templating languages out there already (to name a few: Thymeleaf, Velocity, Handlebars, Freemarker, JTwig) developers could leverage the collective knowledge of a larger community than just AEM developers.
One of the arguments I hear forHTL is that it “makes it easier for front end developers to concentrate on Front-End and back end developers to concentrate on back end”. This is, in my opinion, a load of crock.
Does anyone really believe that the hard part about AEM development is creating basic components which can easily be mocked up in HTML? The hard part is designing the authoring experience, managing the content and data flows / relationships and creating a taxonomy to support the business needs without being unnecessarily complex. Making a templating language look like HTML only makes the language harder to read and understand.
Indeed, I would argue that Handlebars and JTwig, with their radically different control syntax are far superior in this regard as it’s easy to tell at a glance what is code and what is markup. This is of course, a matter of opinion, but I just have a hard time buying the argument where making something look like something it’s not makes it easier to understand.
There is one area where HTL is undoubtedly superior to JSP: security by default. HTL uses the syntax of the current expression to determine the correct escaping method for the content. This can be overridden, but in most cases offers a reasonable default. JSP, on the other hand, writes out unescaped by default. In fact, until version 2.2.4 of the Sling JSP Taglib, there wasn’t a mechanism to encode content without using scriptlet in Apache Sling.
This is important as correctly escaping content prevents Cross Site Scripting (XSS) attacks and will also help with unexpected markup issues from authors using extended characters (such as ampersands or angle brackets) within basic text fields.
While this now can be done with JSP, it does require the additional step of using the sling:encode EL function or tag. This is not hard to do, but JSP does require the additional step vs. HTL and thus introduces more opportunities to miss an XSS issue.
Clearly, I have no love lost with HTL. I am more productive writing JSP code and I believe most developers would be as well, as long as they avoid Scriptlet and leverage the Sling JSP Taglib and Sling Models.
Ultimately, your choice in templating language really boils down to what your team is most comfortable with. For simple development, HTL works acceptably. I would highly encourage any team developing with HTL to develop a reusable set of Sling Models as I describe in Developing Clean and Efficient Lists of Items with HTL to avoid “Death by Models” so similar components share Models instead of recreating the wheel.
Hopefully this post helps shake some of the stigma JSP has received in the AEM community. Unfortunately, JSP was conflated with the bad JSP code in AEM, rather than the potential JSP has as a templating language.