Customization is also possible via the TagDecorator element, but it's some effort to achieve your goal.
But be careful: The solution only works, if there is no <ui:param>
inside the <ui:include>
.
The following four TODOs are necessary:
- Define a wrapper-tag inside your taglib.xml
<namespace>http://my-namespace.com/tags/my-tags</namespace>
<tag>
<tag-name>includeWithComment</tag-name>
<source>my/package/includeWithComment.xhtml</source>
<attribute>
<name>src</name>
</attribute>
</tag>
- Create the xhtml for your wrapper includeWithComment.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:composition>
<!-- START ${src} -->
<ui:include src="${src}" />
<!-- END ${src} -->
</ui:composition>
</html>
- Define your TagDecorator in web.xml like this:
<context-param>
<param-name>javax.faces.FACELETS_DECORATORS</param-name>
<param-value>my.package.CommentTagDecorator</param-value>
</context-param>
- Create your TagDecorator and fill it with life. (Taken from this blogpost)
package my.package;
public class CommentTagDecorator implements TagDecorator {
@Override
public Tag decorate(Tag tag) {
if (!tag.getNamespace().equals("http://xmlns.jcp.org/jsf/facelets")
|| !tag.getLocalName().equals("include")
) {
return null;
}
return new Tag(tag.getLocation(), "http://my-namespace.com/tags/my-tags",
"includeWithComment", "t:includeWithComment", tag.getAttributes());
}
}
Finally your output will look like
<!-- START /include/popup.xhtml -->
[...]
<!-- END /include/popup.xhtml -->