gpt4 book ai didi

jsf-2 - 使用ui时避免使用多个DOCTYPE和html标签 :include

转载 作者:行者123 更新时间:2023-12-02 00:30:26 25 4
gpt4 key购买 nike

我们在“主”页面中使用了几个ui:include 标签。要包含的页面如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=".." xmlns:ui="..." ...>
<ui:fragment rendered="${foo}">
some html code
</ui:fragement>
<ui:fragment rendered="${!foo || bar}">
some more html code
</ui:fragement>
</html>

使用 ui:include 进行模板化会导致在源代码中多次重复 DOCTYPEhtml 标记,这非常难看. (当然,用户看不到,但我是 tidy html 的粉丝)

但是,如果我从 to-be-included-xhtml 中删除 DOCTYPEhtml 标记,Faces Servlet 会抛出一个异常,指出前缀 ui:fragment 的 ui 未绑定(bind)。

有谁知道,我如何多个DOCTYPEhtml来包含另一个XHTML页面?

最佳答案

您应该看看 ui:composition 标签。我们还使用 ui:include 来包含 jsf2 页面,并解决您遇到的问题我相信您可以通过添加 ui:composition 标记来更改包含的页面,如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=".." xmlns:ui="..." ...>
<ui:composition>
<ui:fragment rendered="${foo}">
some html code
</ui:fragement>
<ui:fragment rendered="${!foo || bar}">
some more html code
</ui:fragement>
</ui:composition>
</html>

关于jsf-2 - 使用ui时避免使用多个DOCTYPE和html标签 :include,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7103789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com