有many other topics关于如何覆盖 JSF 中现有的渲染器。所有这些都导致faces-config 中的相同条目。你“只”需要一个 component-family
, renderer-type
, render-kit-id
以及您在 renderer-class
中的实现
我理解并可以重现所有这些示例,但在我的特定情况下,我想覆盖 <ui:include>
的行为和 <ui:insert>
.遗憾的是,我无法找出我必须在上述属性中放入哪些值,因为文件 ui:taglib.xml
不像其他标签库那样冗长。
你有什么想法,如何覆盖它们?
编辑: BalusC 提到 another topic ,它使用自定义标签,如 <my:include>
或 <my:insert>
,但这些我不想使用。如果我这样做,我必须重构我所有现有的代码,如果不使用我的自定义 taglib,我 future 的代码将无法工作。
我想在<ui:include>
的渲染之前hook和 <ui:insert>
所以我可以重用我即将开发的插件 没有 更改任何现有代码。
最佳答案
... without changing any of the existing code
你不能。至少,并非没有与特定实现(Mojarra 或 MyFaces)紧密耦合。另一种选择是硬着头皮更换所有
<ui:include>
和 <ui:define>
来自 <my:include>
和 <my:define>
. Facelets 尚未完全抽象/标准化为 JSF 规范。只有一个 Facelet cache factory ,但没有 Facelet 上下文工厂,否则会很容易。一般来说,忘记定制<ui:xxx>
以抽象的方式标记。你需要破解实现。鉴于您使用的是 Mojarra 2.1.19,您需要 copypaste它的
com.sun.faces.facelets.impl.DefaultFaceletContext
类到您的 Web 应用程序项目中,维护其 com.sun.faces.facelets.impl
包裹。 WAR 中的类比 WAR 中的类具有更高的类加载优先级 /WEB-INF/lib
和服务器的 /lib
.所以你的 WAR 中的这个将被使用。鉴于您想达到与 Customize ui:include rendering to add prefix/postfix 中所要求的相同的效果在
<ui:include>
和 <ui:define>
:Example, supposing a blank file.xhtml:
Input
<ui:include src="file.xhtml" />
Output
<!-- START file.xhtml --> <!-- END file.xhtml -->
以下是通过编辑复制粘贴的
DefaultFaceletContext
来实现它的方法。类(class):private static UIComponent createComment(String comment) {
UIOutput text = new UIOutput();
text.setValue("\n<!-- " + comment + " -->\n");
return text;
}
includeFacelet(UIComponent, String)
在第 199 行,如下所示:parent.getChildren().add(createComment("START INCLUDE " + relativePath));
facelet.include(this, parent, relativePath);
parent.getChildren().add(createComment("END INCLUDE " + relativePath));
includeDefinition(UIComponent, String)
围绕第 366 行 client.apply(this, parent, name)
如下:int start = parent.getChildCount();
found = client.apply(this, parent, name);
if (found) {
parent.getChildren().add(start, createComment("START DEFINE " + name));
parent.getChildren().add(createComment("END DEFINE " + name));
}
然而,在测试期间,我发现了一个警告。我有我的 HTML
<title>
模板化如下:<h:head>
<title><ui:insert name="title">#{view.viewId}</ui:insert></title>
</h:head>
评论因此也最终在
<title>
中元素。不幸的是,HTML 标题中的注释是 invalid语法(仅 PCDATA
允许),它们按字面解释,因此显示在文档标题中。您可能想根据 name
创建黑名单定义或者可能是 parent
.
关于jsf - 覆盖用户界面 :insert and ui:include-Handler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33263233/