自定义ui:include渲染以添加前缀/后缀 [英] Customize ui:include rendering to add prefix/postfix

查看:286
本文介绍了自定义ui:include渲染以添加前缀/后缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要自定义ui:include渲染器,使其在生成HTML输出时还添加一条注释,说明包含文件的开始和结束.

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.

例如,假设空白file.xhtml:

输入

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

输出

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

目前我将JSF2.2与MyFaces结合使用,对如何做到这一点有任何想法吗?

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

推荐答案

我建议定义以下facelet标记:

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>

并在代码中使用此标记代替ui:include:

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>

这篇关于自定义ui:include渲染以添加前缀/后缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆