Expand my Community achievements bar.

SOLVED

Purpose of creating custom tag library?

Avatar

Level 9

Hi All,

https://helpx.adobe.com/experience-manager/using/customtags.html mentions this in detail. However, I need some clarification on the below :

1] So, custom tag library is probably used because we can set the required properties in the tld file and invoke the corresponding java code?

1 Accepted Solution

Avatar

Correct answer by
Employee

I'm not sure I understand the question. If you are asking why use tag libraries? Then this is best practice in web development and not AEM specific. There is a good explanation here, from [0]:

"Tag libraries allow a cleaner separation between the look-and-feel of your application and its logic, compared to the original scriptlet syntax offered by JSP. Replacing scriptlets with custom tags eliminates the awkward confusion of imperative Java and declarative markup that used to be common in JSPs.

In an ideal world, web designers would be able to edit JSP files using a combination of standard markup and custom tags. Common markup patterns can be factored out into tag files; if they need something that requires new logic, a programmer can implement a tag class for them."

You really want to avoid the use of scriptlets in your JSP's, as it makes your code more error prone as you can't write unit tests for the logic. You should investigate using Sightly and Sling models [1][2]

[0]http://stackoverflow.com/questions/1535874/what-is-the-use-of-tag-libraries-in-jsp-and-why-we-are-us...

[1] http://adapt.to/2014/en/schedule/the-lazy-aem-developer--sling-models-sightly-in-action-.html

[2] https://helpx.adobe.com/experience-manager/using/sling_models.html

View solution in original post

1 Reply

Avatar

Correct answer by
Employee

I'm not sure I understand the question. If you are asking why use tag libraries? Then this is best practice in web development and not AEM specific. There is a good explanation here, from [0]:

"Tag libraries allow a cleaner separation between the look-and-feel of your application and its logic, compared to the original scriptlet syntax offered by JSP. Replacing scriptlets with custom tags eliminates the awkward confusion of imperative Java and declarative markup that used to be common in JSPs.

In an ideal world, web designers would be able to edit JSP files using a combination of standard markup and custom tags. Common markup patterns can be factored out into tag files; if they need something that requires new logic, a programmer can implement a tag class for them."

You really want to avoid the use of scriptlets in your JSP's, as it makes your code more error prone as you can't write unit tests for the logic. You should investigate using Sightly and Sling models [1][2]

[0]http://stackoverflow.com/questions/1535874/what-is-the-use-of-tag-libraries-in-jsp-and-why-we-are-us...

[1] http://adapt.to/2014/en/schedule/the-lazy-aem-developer--sling-models-sightly-in-action-.html

[2] https://helpx.adobe.com/experience-manager/using/sling_models.html