jsfjsf-2customizationfaceletsuiinclude

Customize ui:include rendering to add prefix/postfix


I need to customize the ui:include renderer in a way that when it generates the HTML output also adds a comment stating the starting and the ending of the included file.

Example, supposing a blank file.xhtml:

Input

<ui:include src="file.xhtml" />

Output

<!-- START file.xhtml -->
<!-- END file.xhtml -->

At the moment I'm using JSF2.2 with MyFaces, any idea on how I could do that?


Solution

  • I would suggest to define following facelet tag :

    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:c="http://java.sun.com/jsp/jstl/core"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:h="http://java.sun.com/jsf/html"
                >
    <ui:composition>   
      <h:outputText value="&lt;START FILE!--#{source}--&gt;"/>
      <ui:include src="#{source}">
        <ui:insert name="includeParams"/>
      </ui:include>
      <h:outputText value="&lt;!--END FILE!--#{source}--&gt;"/>
    </ui:composition>
    </html>
    

    and to use this tag instead ui:include in the code :

    <my:include source="file.xhtml">
      <ui:define name="includeParams">
        <ui:param name="param1" value="value1"/>      
        <ui:param name="param2" value="value2"/>      
      </ui:define>
    </my:include>